Skip to content

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

Merged
spydon merged 1 commit into
mainfrom
parity/storage-service-error-code
Aug 14, 2026
Merged

spydon merged 1 commit into
mainfrom
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_codes → implemented. Symbol, drift and schema checks pass locally.

Summary by CodeRabbit

  • Bug Fixes

    • Storage errors now consistently preserve service-provided error codes.
    • Added fallback handling when the primary error-code field is unavailable.
    • Download errors now retain the correct status code and message.
  • Documentation

    • Updated storage error-code examples to reflect current identifiers.
  • Tests

    • Added coverage for error-code parsing, fallback behavior, missing codes, status codes, and messages.

@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

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 622637b8-c505-48e5-a097-cced851d6a9d

📥 Commits

Reviewing files that changed from the base of the PR and between a2a9eea and 918767e.

📒 Files selected for processing (4)
  • packages/storage_client/lib/src/types.dart
  • packages/storage_client/test/basic_test.dart
  • packages/storage_client/test/types_test.dart
  • packages/supabase_common/lib/src/supabase_exception.dart

📝 Walkthrough

Walkthrough

StorageApiException.fromJson now reads service error codes from code, falls back to error, and preserves null when neither exists. Tests cover parsing and download responses. Storage exception documentation now uses NoSuchKey.

Changes

Storage error code handling

Layer / File(s) Summary
Error code parsing and documentation
packages/storage_client/lib/src/types.dart, packages/supabase_common/lib/src/supabase_exception.dart
StorageApiException.fromJson prefers code and falls back to error. Documentation uses NoSuchKey as the storage error-code example.
Error code parsing and download tests
packages/storage_client/test/types_test.dart, packages/storage_client/test/basic_test.dart
Tests cover preferred codes, fallback values, absent codes, status codes, messages, and download error responses.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 91876

The change exposes the storage service error code through the existing exception field with a documented fallback, and no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: grdsdev, dshukertjr

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the storage change: exposing the service error code on StorageException.
Linked Issues check ✅ Passed The implementation exposes errorCode, applies code-to-error fallback parsing, updates documentation, and adds tests for required behaviors [#1650].
Out of Scope Changes check ✅ Passed All changes support the linked issue by implementing error-code parsing, testing the behavior, or updating related documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch parity/storage-service-error-code

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
@spydon
spydon force-pushed the parity/storage-service-error-code branch from 267c922 to 5466fab Compare August 6, 2026 09:16
@spydon
spydon force-pushed the refactor/shared-http-fetch-pieces branch 3 times, most recently from 10c4876 to ed0630f Compare August 13, 2026 09:05
@spydon
spydon force-pushed the parity/storage-service-error-code branch from 5466fab to 4628c76 Compare August 13, 2026 09:09
@spydon
spydon force-pushed the refactor/shared-http-fetch-pieces branch from ed0630f to a26a9e8 Compare August 13, 2026 10:23
@spydon
spydon force-pushed the parity/storage-service-error-code branch from 4628c76 to 381f3fd Compare August 13, 2026 10:23
@spydon
spydon force-pushed the refactor/shared-http-fetch-pieces branch from cc3d836 to 5452239 Compare August 14, 2026 09:03
Base automatically changed from refactor/shared-http-fetch-pieces to main August 14, 2026 09:09
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 381f3fd to 918767e Compare August 14, 2026 09:28
@spydon
spydon merged commit 4f9cabf into main Aug 14, 2026
43 checks passed
@spydon
spydon deleted the parity/storage-service-error-code branch August 14, 2026 09:51
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.

parity(storage): expose service error code on storage error type [from supabase-js]

2 participants