yoshidan / google-cloud-rust

Google Cloud Client Libraries for Rust.
MIT License
241 stars 86 forks source link

`google_cloud_storage::client::Client::default()` panics #245

Closed cpick closed 5 months ago

cpick commented 6 months ago

With google-cloud-storage 0.16.0 the following src/main.rs:

fn main() {
    google_cloud_storage::client::Client::default();
}

Panics with:

RUST_BACKTRACE=1 cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.12s
     Running `target/debug/delme-google-cloud-storage`
thread 'main' panicked at /Users/cpick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/google-cloud-token-0.1.2/src/lib.rs:22:9:
This is dummy token source provider. you can use 'google_cloud_default' crate
stack backtrace:
   0: rust_begin_unwind
             at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/std/src/panicking.rs:647:5
   1: core::panicking::panic_fmt
             at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/panicking.rs:72:14
   2: <google_cloud_token::NopeTokenSourceProvider as google_cloud_token::TokenSourceProvider>::token_source
             at /Users/cpick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/google-cloud-token-0.1.2/src/lib.rs:22:9
   3: google_cloud_storage::client::Client::new
             at /Users/cpick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/google-cloud-storage-0.16.0/src/client.rs:151:31
   4: <google_cloud_storage::client::Client as core::default::Default>::default
             at /Users/cpick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/google-cloud-storage-0.16.0/src/client.rs:143:9
   5: delme_google_cloud_storage::main
             at ./src/main.rs:2:5
   6: core::ops::function::FnOnce::call_once
             at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Which appears to be because ClientConfig::default() sets token_source_provider: Some(Box::new(NopeTokenSourceProvider {})), and then Client::new() calls config.token_source_provider.token_source() which panics.

Based on the code in Client::new() I believe it's expecting a TokenSourceProvider to be None in that situation instead?

yoshidan commented 5 months ago

Currently Client::default() does not work. (It is planned to be removed.)

You need to set a valid token_source_provider in ClientConfig as shown in the following code.

let storage_config = google_cloud_storage::client::ClientConfig::default()
    .with_auth()
    .await?
let storage_client = google_cloud_storage::client::Client::new(storage_config);
yoshidan commented 5 months ago

I removed the google_cloud_storage::client::Client::default()