Skip to content

Bug: supabaseIntegration crashes when PostgREST response is nullish #20032

@antonis

Description

@antonis

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/react-native (via @sentry/core supabase integration re-exported by @sentry/browser)

SDK Version

8.6.0

Framework Version

React Native

Link to Sentry event

SDK crash detection event — internal to Sentry

Steps to Reproduce

  1. Use supabaseIntegration in a React Native app
  2. Perform a PostgREST query (e.g. supabase.from('table').select('*'))
  3. Under certain conditions (likely related to RN's fetch implementation or a custom fetch passed to the Supabase client), the PostgREST response resolves with undefined instead of the expected { data, error, status } object

Expected Result

The integration should handle a nullish response gracefully without crashing.

Actual Result

The SDK crashes with an unhandled Error (empty message) at instrumentPostgRESTFilterBuilder in supabase.ts.

The crash occurs in the .then() success handler after Reflect.apply(target, thisArg, []), where res.error is accessed without a null check on res:

https://github.com/getsentry/sentry-javascript/blob/0ccab39ff4e498228ntonio/packages/core/src/integrations/supabase.ts#L342

// Current code (crashes when res is nullish):
(res: SupabaseResponse) => {
  if (res && typeof res === 'object' && 'status' in res) {
    setHttpStatus(span, res.status || 500);
  }
  span.end();

  if (res.error) {  // 💥 TypeError if res is undefined

Notably, the auth instrumentation in the same file already guards against this correctly:

// Auth path (safe):
if (res && typeof res === 'object' && 'error' in res && res.error) {

Additional Context

This was detected via Sentry's SDK crash detection (sdk_crash_detection context). The mechanism is auto.db.supabase.postgres, confirming it's the PostgREST path.

Why this appears to be React Native-specific:

PostgREST's .then() is a custom thenable that internally calls fetch(), processes the response in an async callback, and returns internalPromise.then(onfulfilled, onrejected). When Sentry calls it with no arguments (Reflect.apply(target, thisArg, [])), both callbacks are undefined, so the resolved value should pass through per the Promise/A+ spec.

However, React Native uses its own native-bridged fetch implementation (not the browser's), and users often provide a custom fetch to the Supabase client as recommended by Supabase docs. If the fetch resolves differently (e.g., on network errors or timeouts), the PostgREST async handler could exit without an explicit return, resolving with undefined.

Suggested fix:

Guard res before accessing .error, consistent with the auth handler:

if (res && res.error) {

Or use optional chaining throughout the success handler.

Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Metadata

Metadata

Assignees

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions