fix(storage)!: correct exists() error handling for non-existent files#1745
Open
fix(storage)!: correct exists() error handling for non-existent files#1745
Conversation
2 tasks
itslenny
requested changes
Oct 23, 2025
Contributor
|
@mandarini Ya let me look into it. |
Contributor
|
@itslenny I think this can work if (status && [400, 404].indexOf(status) !== -1) {
return { data: false, error }
}Users checking if (error) will correctly trigger the "not exists" logic when files don't exist The Return Type Supports It Promise<
| { data: boolean; error: null }
| { data: boolean; error: StorageError }
>The change ensures that users can properly handle both "file exists" and "file doesn't exist" scenarios using the error field, which is the standard pattern in Supabase APIs. |
Contributor
Author
|
I will be parking this PR for now, since it will be a breaking change. We will consider this change for our v3 release. Thank you @SumitKumar-17 |
Contributor
|
Okay @mandarini |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
authored by @SumitKumar-17
Transfered from: supabase/storage-js#256
Bug Fix Report
I have successfully identified and fixed the bug reported in the
issue. Here's what I found and resolved:
The Issue
The bug report was partially correct. The
existsmethod was indeedpresent in both browser and Node.js builds (I confirmed it existed
in the compiled output), but there was an error handling bug that
made it appear to not work properly in certain cases.
The Root Cause
The problem was in the error handling logic of the
existsmethod insrc/packages/StorageFileApi.ts. When a file doesn't exist(resulting in a 404 HTTP status), the method would return
{ data: false, error: StorageError }instead of{ data: false, error: null }.This was incorrect behavior because:
operation failed
{ data: false, error: null }to indicate"file doesn't exist, but the check was successful"
The Fix
I updated the
existsmethod to properly handle bothStorageApiError(which contains the status code directly) andStorageUnknownError(which contains the original error object),and return
{ data: false, error: null }when the error status is400 or 404.
Changes Made
existsmethod to properly return{ data: false, error: null }when a file doesn't existStorageApiErrorexistsmethodVerification
Solves: #1600
Breaking change
This is a breaking change, and it can be added in the v3 planning.