Skip to content

fix(storage): wrap non-StorageError exceptions in StorageUnknownError - #2554

Closed
PedroHenrique0713 wants to merge 1 commit into
supabase:masterfrom
PedroHenrique0713:fix/handleoperation-non-storage-error
Closed

fix(storage): wrap non-StorageError exceptions in StorageUnknownError#2554
PedroHenrique0713 wants to merge 1 commit into
supabase:masterfrom
PedroHenrique0713:fix/handleoperation-non-storage-error

Conversation

@PedroHenrique0713

Copy link
Copy Markdown
Contributor

Summary

handleOperation's documented contract is to always return { data, error } tuples. However, when the operation threw a non-StorageError exception (JSON parse failure, TypeError from missing fetch, etc.), the error was re-thrown instead of being wrapped.

Fix: Wrap non-StorageError exceptions in StorageUnknownError and return { data: null, error }.

handleOperation's documented contract is to return { data, error } tuples.
When a non-StorageError was thrown, the error was re-thrown instead of
being wrapped, breaking the expected caller contract.
@PedroHenrique0713
PedroHenrique0713 requested review from a team as code owners July 23, 2026 20:59
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for unexpected storage operation failures.
    • When configured not to throw errors, operations now return a structured unknown-error response instead of unexpectedly terminating.

Walkthrough

BaseApiClient.handleOperation now converts unknown, non-StorageError failures into typed responses when shouldThrowOnError is disabled. The response contains data: null and a StorageUnknownError whose message is derived with _getErrorMessage. When throwing is enabled, existing error behavior remains unchanged.


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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core/storage-js/src/lib/common/BaseApiClient.ts`:
- Around line 101-104: Update the error construction in BaseApiClient to pass
this.namespace as the third argument to StorageUnknownError, preserving the
configured vectors or storage namespace while leaving the existing message and
cause unchanged.
- Line 103: Update the error handling around _getErrorMessage in BaseApiClient
so extracting a message cannot throw for arbitrary values, including circular
references or bigint; ensure the catch always returns the documented { data:
null, error } tuple by using a safe fallback message, either locally or by
making _getErrorMessage total.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d0305f78-e429-402a-8d09-af385c0dfd86

📥 Commits

Reviewing files that changed from the base of the PR and between 485695f and 8c8117a.

📒 Files selected for processing (1)
  • packages/core/storage-js/src/lib/common/BaseApiClient.ts

Comment on lines +101 to +104
return {
data: null,
error: new StorageUnknownError(_getErrorMessage(error), error) as unknown as TError,
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Preserve the client error namespace.

BaseApiClient supports the vectors namespace, but this constructor call uses StorageUnknownError’s default 'storage' namespace. Vector clients will therefore receive the wrong error name/type. Pass this.namespace as the third constructor argument.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core/storage-js/src/lib/common/BaseApiClient.ts` around lines 101 -
104, Update the error construction in BaseApiClient to pass this.namespace as
the third argument to StorageUnknownError, preserving the configured vectors or
storage namespace while leaving the existing message and cause unchanged.

throw error
return {
data: null,
error: new StorageUnknownError(_getErrorMessage(error), error) as unknown as TError,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Do not let message extraction escape the error handler.

_getErrorMessage falls back to JSON.stringify, which throws for values containing circular references or bigint. Because it runs inside this catch, such inputs are re-thrown instead of returning the documented { data: null, error } tuple. Guard the extraction with a fallback message, or make _getErrorMessage total for arbitrary thrown values.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core/storage-js/src/lib/common/BaseApiClient.ts` at line 103, Update
the error handling around _getErrorMessage in BaseApiClient so extracting a
message cannot throw for arbitrary values, including circular references or
bigint; ensure the catch always returns the documented { data: null, error }
tuple by using a safe fallback message, either locally or by making
_getErrorMessage total.

@PedroHenrique0713

Copy link
Copy Markdown
Contributor Author

Closing this one. I opened it today as part of a batch of stacked branches, and it went out without the test coverage I normally include. I already have open PRs in this repo (#2514, #2518, #2529, #2530) that carry unit and end-to-end tests, and I would rather keep the review queue focused on those. If this fix still applies, I will resubmit it properly tested on top of master. Sorry for the noise.

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.

1 participant