Skip to content

fix(storage): surface real error when error body lacks message - #1567

Open
MRoshaan wants to merge 1 commit into
supabase:mainfrom
MRoshaan:fix/storage-error-body-missing-message
Open

fix(storage): surface real error when error body lacks message#1567
MRoshaan wants to merge 1 commit into
supabase:mainfrom
MRoshaan:fix/storage-error-body-missing-message

Conversation

@MRoshaan

@MRoshaan MRoshaan commented Aug 8, 2026

Copy link
Copy Markdown

Description

In storage3, when the Storage API returns a non-2xx response whose JSON body is missing any of message, error or statusCode, the error-recovery path accessed resp.text where resp is the already-decoded dict — raising AttributeError: '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 StorageApiError instead.

Changes

  • src/storage3/_sync/file_api.py and src/storage3/_async/file_api.py: use exc.response.text on the recovery path.
  • Added regression tests (tests/_sync/test_file_api.py, tests/_async/test_file_api.py) covering both sync and async _request.

Testing

  • New tests pass for _sync and _async.
  • Adjacent storage unit tests (bucket, exceptions, utils) pass: 28 passed.
  • ruff check and ruff format --check clean on changed files.

Cc: cc @olirice @silentworks for review.

@MRoshaan
MRoshaan requested a review from o-santi as a code owner August 8, 2026 21:56
Copilot AI lite review requested due to automatic review settings August 8, 2026 21:56
@MRoshaan
MRoshaan requested a review from a team as a code owner August 8, 2026 21:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 _request error recovery to use exc.response.text instead of resp.text.
  • Update async _request error recovery to use exc.response.text instead of resp.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

storage3: AttributeError masks the real error when a storage error body lacks message/error/statusCode

2 participants