fix(storage): surface real error when error body lacks message - #1567
Open
MRoshaan wants to merge 1 commit into
Open
fix(storage): surface real error when error body lacks message#1567MRoshaan wants to merge 1 commit into
MRoshaan wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a bug in storage3 request error handling where the fallback path could raise AttributeError (masking the underlying HTTP error) when the decoded JSON body lacks expected keys. The change ensures the fallback error message uses the original HTTP response body text.
Changes:
- Update sync
_requesterror recovery to useexc.response.textinstead ofresp.text. - Update async
_requesterror recovery to useexc.response.textinstead ofresp.text. - Add sync + async regression tests covering the missing-keys error body case.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/storage/src/storage3/_sync/file_api.py | Fixes fallback error message to read raw response text from the HTTPX response. |
| src/storage/src/storage3/_async/file_api.py | Mirrors the sync fix for async requests. |
| src/storage/tests/_sync/test_file_api.py | Adds regression coverage to ensure StorageApiError is raised (not AttributeError) and includes body content. |
| src/storage/tests/_async/test_file_api.py | Adds the async equivalent regression test for _request. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In
storage3, when the Storage API returns a non-2xx response whose JSON body is missing any ofmessage,errororstatusCode, the error-recovery path accessedresp.textwhererespis the already-decodeddict— raisingAttributeError: 'dict' object has no attribute 'text'and completely masking the real error.Motivation
Closes #1563. The real status and body were being discarded exactly when they matter most (the error path). The fix reports the raw response text in a proper
StorageApiErrorinstead.Changes
src/storage3/_sync/file_api.pyandsrc/storage3/_async/file_api.py: useexc.response.texton the recovery path.tests/_sync/test_file_api.py,tests/_async/test_file_api.py) covering both sync and async_request.Testing
_syncand_async.ruff checkandruff format --checkclean on changed files.Cc: cc @olirice @silentworks for review.