question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rust panics when I look for an incorrect id

See original GitHub issue
Deno 1.2.0
TypeScript 3.9.6
MongoDriver 0.9.2

When I try to use findOne() method for searching an incorrect / inexistent ID rust panics and the server crashes. I also try to catch the error, but nothing changes. Is there a way to avoid this tedious problem?

    async show ( ctx : any ) {
        try{
        const data = await user.findOne(
            {_id: {$oid: ctx.params.id}},
            );
             ctx.response.body = data;
        } catch (e) {
            ctx.response.status = 404;
            ctx.response.body = {error: "This isn't the user you're looking for"};

        }
    },
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: FromHexError(OddLength)', /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/bson-0.14.1/src/bson.rs:575:39
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Guillaume-Lebeguecommented, Aug 4, 2020

Ah, yes, you need to import ObjectId from deno_mongo

import { ObjectId } from 'https://deno.land/x/mongo@v0.9.1/mod.ts';

0reactions
manyuanrongcommented, Nov 27, 2020

This problem should no longer exist

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rust Panic when querying a model with @@id #1729 - GitHub
Rust Panic when querying a model with @@id #1729 ... I see this error: PANIC: ... error which probably happens when the Prisma...
Read more >
How do I write a Rust unit test that ensures that a panic has ...
You can find the answer in testing section of the Rust book. More specifically, you want #[should_panic] attribute:
Read more >
Unrecoverable Errors with panic! - The Rust Programming ...
By default, when a panic occurs, the program starts unwinding, which means Rust walks back up the stack and cleans up the data...
Read more >
How to catch panics in test code so that I can clean up ... - Reddit
I am using the built in actix_web::test module to build an App, send a request and then check out the result. I get...
Read more >
1236-stabilize-catch-panic - The Rust RFC Book
It is currently defined as undefined behavior to have a Rust program panic across an FFI boundary. For example if C calls into...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found