denodrivers / mongo

🍃 MongoDB driver for Deno 🦕
https://deno.land/x/mongo
MIT License
512 stars 95 forks source link

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: FromHexError(InvalidHexCharacter { c: 'i', index: 0 }) #123

Closed KirianCaumes closed 4 years ago

KirianCaumes commented 4 years ago

Hello,

I'm trying to add simple test in project, but there is an error blocking me:

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: FromHexError(InvalidHexCharacter { c: 'i', index: 0 })', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/bson-0.14.1/src/bson.rs:575:71

My test look like this:

Deno.test(
    "[POST] Create success",
    async () => {
        await (await superoak(app))
            .post('/api/element')
            .auth(await userFixture.getToken(), { type: "bearer" })
            .send({
                title: faker.commerce.productName(),
                description: faker.company.catchPhraseDescriptor(),                
            })
            .expect("Content-Type", /json/)
            .expect(200)
    }
)

And it's run with this command:

DENO_ENV="test" RUST_BACKTRACE=1 RUST_BACKTRACE=full deno test -c tsconfig.json --allow-net --allow-read --allow-env --allow-write --allow-plugin --unstable tests/

Finally, the stacktrace:

   0:     0x7f9f562fd475 - backtrace::backtrace::libunwind::trace::h14d338b30b3ea0a7
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1:     0x7f9f562fd475 - backtrace::backtrace::trace_unsynchronized::h73ea91d74a3fd67f
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2:     0x7f9f562fd475 - std::sys_common::backtrace::_print_fmt::hd42948c952866e12
                               at src/libstd/sys_common/backtrace.rs:78
   3:     0x7f9f562fd475 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha8f928866ff7571e
                               at src/libstd/sys_common/backtrace.rs:59
   4:     0x7f9f563269cc - core::fmt::write::he0c1e5f7426d2718
                               at src/libcore/fmt/mod.rs:1076
   5:     0x7f9f562f6dd2 - std::io::Write::write_fmt::hf3afc6cfd57d0033
                               at src/libstd/io/mod.rs:1537
   6:     0x7f9f562ff940 - std::sys_common::backtrace::_print::hfc0110703f3696fd
                               at src/libstd/sys_common/backtrace.rs:62
   7:     0x7f9f562ff940 - std::sys_common::backtrace::print::h3f77c6990ddfaa22
                               at src/libstd/sys_common/backtrace.rs:49
   8:     0x7f9f562ff940 - std::panicking::default_hook::{{closure}}::heae49580a8d62d75
                               at src/libstd/panicking.rs:198
   9:     0x7f9f562ff68c - std::panicking::default_hook::hecc34e3f729e213c
                               at src/libstd/panicking.rs:217
  10:     0x7f9f562fff83 - std::panicking::rust_panic_with_hook::he82f5d0644692441
                               at src/libstd/panicking.rs:526
  11:     0x7f9f562ffb7b - rust_begin_unwind
                               at src/libstd/panicking.rs:437
  12:     0x7f9f563250b1 - core::panicking::panic_fmt::h09c929f06bb87c98
                               at src/libcore/panicking.rs:85
  13:     0x7f9f56324ed3 - core::option::expect_none_failed::h188f17af6c9f404b
                               at src/libcore/option.rs:1269
  14:     0x7f9f5629c73b - bson::bson::Bson::from_extended_document::he2522bf514414c7a
  15:     0x7f9f5629a009 - <bson::bson::Bson as core::convert::From<serde_json::value::Value>>::from::hba9e3c77b876a085
  16:     0x7f9f562a49de - <bson::ordered::OrderedDocument as core::iter::traits::collect::FromIterator<(alloc::string::String,bson::bson::Bson)>>::from_iter::hc921d5276510b2e0
  17:     0x7f9f56299ffd - <bson::bson::Bson as core::convert::From<serde_json::value::Value>>::from::hba9e3c77b876a085
  18:     0x7f9f55fd8173 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h5fd3d8403d7f2fbb
  19:     0x7f9f55fa5e39 - <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll::h1e36305f3b278d04
  20:     0x7f9f55fec557 - <futures_util::future::future::flatten::Flatten<Fut,<Fut as core::future::future::Future>::Output> as core::future::future::Future>::poll::hde59b33db7b37fa3
  21:     0x5565c4acb358 - <futures_util::future::future::Inspect<Fut,F> as core::future::future::Future>::poll::h4949e700c75018de
  22:     0x5565c4d5a805 - <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll::h1aae831868fa9192
  23:     0x5565c4d5d123 - <futures_util::stream::futures_unordered::FuturesUnordered<Fut> as futures_core::stream::Stream>::poll_next::h2752795059f8c7c4
  24:     0x5565c4d6caf1 - deno_core::runtime::JsRuntime::poll_event_loop::ha1ac16f9248b91a6
  25:     0x5565c4bff2eb - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hc92eb54ac15f0a05
  26:     0x5565c4cede66 - deno::test_command::{{closure}}::h44ea5729cb4666b4
  27:     0x5565c4c01af8 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hdeb32e3b44020ece
  28:     0x5565c4bbe192 - tokio::runtime::Runtime::block_on::h7148315b848bf24b
  29:     0x5565c4cf3551 - deno::main::hfcf455f2df1a44ec
  30:     0x5565c4b5b495 - std::sys_common::backtrace::__rust_begin_short_backtrace::hcc04b8b81d5e1708
  31:     0x5565c4cfa494 - main
  32:     0x7f9f574d3b97 - __libc_start_main
  33:     0x5565c4aca33a - _start
  34:                0x0 - <unknown>

I'm not sure if it's really related to my test...

Thanks a lot for your help!

manyuanrong commented 4 years ago

I didn't see the code sample for deno_mong. But I guess it has something to do with the value you pass. For example, $oid: "xx" must be a legal id value, if it is illegal, it will exit unexpectedly

89

KirianCaumes commented 4 years ago

Hey, that was it! I didn't see how that could be a problem, knowing that I had already handled these ID issues, but for my tests, I created entities manually and their ids were not correct here. Thank you very much !