Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(storage): avoid crashes when parsing ErrorInfo #8968

Merged
merged 1 commit into from
May 15, 2022

Conversation

coryan
Copy link
Contributor

@coryan coryan commented May 14, 2022

Maybe unsurprisingly, the error payloads are less structured that we
expected. This PR performs additional validation to avoid crashes while
trying to parse these payloads as a ErrorInfo. If we could reliably
use exceptions I would just parse the code and handle any exception in
a single line of code, alas, we cannot.

Fixes #8965


This change is Reviewable

Maybe unsurprisingly, the error payloads are less structured that we
expected. This PR performs additional validation to avoid crashes while
trying to parse these payloads as a `ErrorInfo`.  If we could reliably
use exceptions I would just parse the code and handle any exception in
a single line of code, alas, we cannot.
@product-auto-label product-auto-label bot added the api: storage Issues related to the Cloud Storage API. label May 14, 2022
@google-cloud-cpp-bot
Copy link
Collaborator

Google Cloud Build Logs
For commit: 5b5dfe151431a51ec8494f09432b73cc49011ed9

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@codecov
Copy link

codecov bot commented May 14, 2022

Codecov Report

Merging #8968 (5b5dfe1) into main (f9b3c29) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #8968      +/-   ##
==========================================
- Coverage   94.47%   94.47%   -0.01%     
==========================================
  Files        1421     1421              
  Lines      124916   124931      +15     
==========================================
+ Hits       118012   118024      +12     
- Misses       6904     6907       +3     
Impacted Files Coverage Δ
google/cloud/storage/internal/http_response.cc 98.82% <100.00%> (-1.18%) ⬇️
...oogle/cloud/storage/internal/http_response_test.cc 100.00% <100.00%> (ø)
...e/cloud/pubsublite/internal/alarm_registry_impl.cc 97.05% <0.00%> (-2.95%) ⬇️
...cloud/pubsub/internal/subscription_session_test.cc 98.00% <0.00%> (-0.75%) ⬇️
google/cloud/completion_queue_test.cc 97.13% <0.00%> (+0.19%) ⬆️
...le/cloud/storage/internal/curl_download_request.cc 89.59% <0.00%> (+0.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f9b3c29...5b5dfe1. Read the comment docs.

@coryan coryan marked this pull request as ready for review May 14, 2022 18:41
@coryan coryan requested a review from a team as a code owner May 14, 2022 18:41
Comment on lines +200 to +201
if (!e.contains("message") || !e.contains("details")) return default_error();
if (!e["message"].is_string()) return default_error();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could return a Status(code, e.value("message", "")) if e.contains("message") && e["message"].is_string() && !e.contains("details"), but it's also fine to return the whole payload as a message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

@coryan coryan merged commit 704249c into googleapis:main May 15, 2022
@coryan coryan deleted the fix-storage-parse-invalid-error-info branch May 15, 2022 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

google storage client json throw exception when http request fails
3 participants