Skip to content

feat(storage): expose the service error code on StorageException - #1657

Open
spydon wants to merge 1 commit into
refactor/shared-http-fetch-piecesfrom
parity/storage-service-error-code
Open

feat(storage): expose the service error code on StorageException#1657
spydon wants to merge 1 commit into
refactor/shared-http-fetch-piecesfrom
parity/storage-service-error-code

Conversation

@spydon

@spydon spydon commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Closes #1650. SDK-1426.

Stacked on #1647, which is where StorageException becomes a SupabaseException and its fromJson gets its defensive field reads. Review that one first; the diff here is only the last commit.

Storage answers a failed request with a body like:

{ "statusCode": "404", "error": "not_found", "code": "NoSuchKey", "message": "Object not found" }

code is the documented storage error code and is what STORAGE-629 added to the server's error schema. supabase-js picked it up in supabase/supabase-js#2537 as a new code field on StorageApiError.

The Dart shape

A second code field alongside errorCode would give storage two overlapping identifiers and undo the point of the unified exception in this stack, so code goes into SupabaseException.errorCode instead. That field is already documented as "service specific identifier for the error", which is exactly what this is.

error stays as the fallback for servers that predate the schema change. It is not a good primary source: against a local stack, the same field is not_found for a missing object and Bucket not found for a missing bucket, so it carries a plain sentence about as often as an identifier. code does not have that problem.

try {
  await supabase.storage.from('avatars').download('missing.png');
} on StorageException catch (error) {
  if (error.errorCode == 'NoSuchKey') {
    // ...
  }
}

The example in SupabaseException.errorCode's doc comment moves from not_found to NoSuchKey to match what storage now yields.

Testing

types_test.dart covers the three fromJson branches (code wins over error, error as fallback, null when the body has neither). basic_test.dart covers the same through a real request, so the value survives the fetch layer rather than only the factory.

melos analyze and melos format clean. The full storage_client suite passes against a local stack (220 tests), as does supabase_common.

Compliance matrix

storage.errors.error_codesimplemented. Symbol, drift and schema checks pass locally.

@spydon
spydon requested a review from a team as a code owner August 6, 2026 08:56
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: dc75a1f3-bf9c-471b-a743-a0cad6eae3c1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the storage This issue or pull request is related to storage label Aug 6, 2026
Read the storage error code from the response body's `code` into
SupabaseException.errorCode, falling back to `error` for servers that
predate the schema change.

Closes #1650
@spydon
spydon force-pushed the parity/storage-service-error-code branch from 267c922 to 5466fab Compare August 6, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

storage This issue or pull request is related to storage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants