google-apis-rs / google-cloud-rs

Asynchronous Rust bindings for Google Cloud Platform APIs.
176 stars 48 forks source link

Panic when listing buckets when there are no buckets #40

Closed nlfiedler closed 3 years ago

nlfiedler commented 3 years ago

Using the test code as an example with a GCP project that has no buckets, I get this error:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Reqwest(reqwest::Error { kind: Decode, source: Error("missing field `items`", line: 3, column: 1) })', src/main.rs:30:27

This is my code, which is basically the test code but loading the credentials from a file. Using google-cloud version 0.1 from crates.io:

fn load_creds() -> ApplicationCredentials {
    let filename = env::var("GCP_TEST_CREDENTIALS").expect("env GCP_TEST_CREDENTIALS not set");
    let creds = fs::read_to_string(filename).unwrap();
    serde_json::from_str::<ApplicationCredentials>(&creds)
        .expect("incorrect application credentials format")
}

async fn setup_client() -> Result<storage::Client, storage::Error> {
    let creds = load_creds();
    let project = env::var("GCP_TEST_PROJECT").expect("env GCP_TEST_PROJECT not set");
    storage::Client::from_credentials(project, creds).await
}

async fn storage_lists_buckets() {
    let mut client = setup_client().await.unwrap();
    let buckets = client.buckets().await.unwrap(); // <<---- line 30 of main.rs
    for bucket in buckets.iter() {
        println!("bucket: {}", bucket.name());
    }
}
Hirevo commented 3 years ago

Hello,

Thanks for spotting and reporting this bug, it indeed passed completely unobserved during my testing.
I've committed a fix for this in #42 which should land very soon in the next crates.io release.

Thanks again for filing the issue

nlfiedler commented 3 years ago

Excellent, works splendidly, thanks.