'Only in debug session, parsing mongodb connection string fails on unwrap (rust)

let mut client_options = ClientOptions::parse(
    env::var("MONGODB_CONNECTION_STRING").unwrap_or("".to_string())
)
.await
.unwrap();

This code runs fine without debugging. When in debug session it will show:

thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: InvalidArgument { message: "connection string contains no scheme" }, labels: {} }', src/main.rs:73:6
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

My connection string is in .cargo/config.toml as:

[env]
MONGODB_CONNECTION_STRING="mongodb+srv://xxxxxxx:<password>@xxxxxx.xxxxxxx.mongodb.net/sample_restaurants?retryWrites=true&w=majority"

What's wrong here?



Solution 1:[1]

hmm it's not related.

Summary: debug session fail to parse mongo connection string at unwrap

  • env variable in /project/.cargo/config.toml

debug session OK to parse mongo connection string if setting as:

  • OS env variable
  • "env" in launch.json

If no advice arrive I will go to CodeLLDB :)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 yk2021-yeah