Skip to content

fix(postgrest): wrap error in PostgrestError instance on processResponse#2240

Open
Vansh1811 wants to merge 1 commit intosupabase:masterfrom
Vansh1811:fix/postgrest-error-instanceof-1643
Open

fix(postgrest): wrap error in PostgrestError instance on processResponse#2240
Vansh1811 wants to merge 1 commit intosupabase:masterfrom
Vansh1811:fix/postgrest-error-instanceof-1643

Conversation

@Vansh1811
Copy link
Copy Markdown
Contributor

Problem

The error field returned by processResponse in PostgrestBuilder is a plain object literal, not an instance of PostgrestError. This means error instanceof PostgrestError checks always return false, breaking error type-narrowing for consumers.

Related issue: supabase/postgrest-js#1643

Fix

Wrap the error field in the final return statement with new PostgrestError(error) when the error is non-null, so that instanceof checks work correctly.

// Before
error,

// After
error: error ? new PostgrestError(error) : null,

This is consistent with the existing throw new PostgrestError(error) on line 460 for the shouldThrowOnError path.

Testing

Consumers can now reliably narrow the error type:

const { error } = await supabase.from('table').select()
if (error instanceof PostgrestError) {
  // This now works correctly
  console.log(error.code, error.message)
}

Fixes the issue where `error` returned from processResponse is a plain object instead of a PostgrestError instance, breaking `error instanceof PostgrestError` checks.

The error field now wraps non-null errors with `new PostgrestError(error)` so consumers can reliably use instanceof checks.

Fixes supabase/postgrest-js#1643
@Vansh1811 Vansh1811 requested review from a team as code owners April 10, 2026 06:17
@steve-chavez
Copy link
Copy Markdown
Member

Related issue: supabase/postgrest-js#1643

I'm unable to find the reference so don't understand the motivation here, please share the full link.

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.

2 participants