Skip to content

fix(storage): exists reports invalid JWT or missing bucket as missing file - #2783

Merged
cmelchior merged 1 commit into
masterfrom
cm/fix/exists-wrong-return-value
Oct 22, 2026
Merged

cmelchior merged 1 commit into
masterfrom
cm/fix/exists-wrong-return-value

Conversation

@cmelchior

@cmelchior cmelchior commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🔍 Description

What changed?

StorageFileApi.exists() now reads the object info (GET /object/info/...) instead of sending a HEAD request.

  • Returns { data: true, error: null } when the object is found.
  • Returns { data: false, error } only for NoSuchKey, or a 404 with no error code.
  • Rethrows everything else: InvalidJWT, NoSuchBucket, other 4xx/5xx, and network errors.
  • With throwOnError(), a missing object throws as before.
  • Docs on exists describe these cases, and unit tests cover each one.

Why was this change needed?

A HEAD response has no body, so the client could not tell an invalid or expired JWT (400) or a missing bucket (404) from a missing object. exists() treated every 400 and 404 as "file does not exist" and returned false.

This is consistent with changes made in Swift and Flutter: https://linear.app/supabase/issue/SDK-2286/drift-storagefile-bucketsfile-exists-js

🔄 Breaking changes

exists() previously returned false for any 400. It now throws for a 400 that is not a missing key, such as InvalidJWT. Callers that relied on false for those cases now get the real error.

  • This PR contains no breaking changes

📋 Checklist

  • I have read the Contributing Guidelines
  • My PR title follows the conventional commit format: <type>(<scope>): <description>
  • I have run pnpm nx format to ensure consistent code formatting
  • I have added tests for new functionality (if applicable)
  • I have updated documentation (if applicable)

🤖 Generated with Claude Code

…ng file

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@cmelchior
cmelchior requested review from a team as code owners October 22, 2026 09:28
@github-actions github-actions Bot added the storage-js Related to the storage-js library. label Oct 22, 2026
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d0a6a2f4-8cea-4cd9-a6ec-43d990a496d3
📥 Commits

Reviewing files that changed from the base of the PR and between 5adfffe and 4b80798.

📒 Files selected for processing: 2
  • packages/core/storage-js/src/packages/StorageFileApi.ts
  • packages/core/storage-js/test/storageFileApiErrorHandling.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved file existence checks to return false for missing objects while preserving errors for other failures.
    • Network errors and missing-object errors now follow the configured error-handling behavior.

The exists method now calls info(path) to check object metadata. It returns true when the lookup succeeds. It returns false with the original error for NoSuchKey or an HTTP 404 without an error code. It throws other errors, and it throws missing-object errors when throwOnError() is enabled. Tests cover these outcomes.

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 4b807

The existence check distinguishes missing objects from authentication and other failures. No actionable merge-blocking risk was established.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@pkg-pr-new

pkg-pr-new Bot commented Oct 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@2783

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@2783

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@2783

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@2783

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@2783

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@2783

commit: 4b80798

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 82.263% (+0.08%) from 82.185% — cm/fix/exists-wrong-return-value into master

@cmelchior
cmelchior merged commit db8c3a4 into master Oct 22, 2026
32 checks passed
@cmelchior
cmelchior deleted the cm/fix/exists-wrong-return-value branch October 22, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

storage-js Related to the storage-js library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants