Byron / google-apis-rs

A binding and CLI generator for all Google APIs
http://byron.github.io/google-apis-rs
Other
1.02k stars 136 forks source link

[Sheets API] Error after reading unformatted numbers #233

Closed Goncalerta closed 3 years ago

Goncalerta commented 5 years ago

Given spreadsheet with the number 5 on cell A1, the following request:

hub
        .spreadsheets()
        .values_get(spreadsheet_id, "Sheet1!A1:A1")
        .value_render_option("UNFORMATTED_VALUE")
        .add_scope(Scope::Spreadsheet)
        .doit()
        .unwrap();

panics with:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: JsonDecodeError("{\n  \"range\": \"\'Sheet1\'!A1\",\n  \"majorDimension\": \"ROWS\",\n  \"values\": [\n    [\n
   5\n    ]\n  ]\n}\n", Error("invalid type: integer `5`, expected a string", line: 6, column: 7))', src/libcore/result.rs:997:5

This happens because, with the UNFORMATTED_VALUE render option, the API will return numbers instead of strings as the cell value, however, google_sheets4::ValueRange only accepts Strings as cell values.

Byron commented 5 years ago

Thanks a lot for posting the issue, I think it's clear and easy to understand. With #231 , I believe these cases can be circumvented. Even though this crate will try its best to provide preset types for return values of the google APIs, there may always be cases where those won't match reality. In #231, the caller is able to provide their own structures with exactly the type they expect. I think a first version of said PR is going to land in an update soon(ish), which should help you solve this issue.

Byron commented 3 years ago

Maybe you could try with the latest version of the crates now available with async support in v2.0 or the next generation of API generators.

As this repository is now in maintenance mode, this issue is probably not going to be fixed unless it is contributed.