supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.

Home Page:https://supabase.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Errors are missing stack trace

meyer9 opened this issue · comments

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Errors returned do not include a stack trace because they are throwing a plain object instead of an Error. This makes it annoying to track down the root cause of an error because there's no way to tell where it was thrown from.

To Reproduce

Write a postgrest-js query that returns an error. Notice that error.stack is undefined and error instanceof Error is false.

import { PostgrestClient } from 'https://esm.sh/@supabase/postgrest-js@1.8.5';

const REST_URL = 'http://localhost:54321/rest/v1';
const postgrest = new PostgrestClient(REST_URL);

try {
  const { data } = await postgrest
    .from('does_not_exist')
    .select('*')
    .throwOnError();

  console.log(`Got data: ${data}`);
} catch (err) {
  console.log(err);
  console.log(err.stack);
  console.log(err instanceof Error);
}

// {
//   code: "42P01",
//   details: null,
//   hint: null,
//   message: 'relation "public.does_not_exist" does not exist'
// }
// undefined
// false

Expected behavior

I expect stack to be set on the result. I think it might be good to return a PostgrestError that extends Error with the error details, but also just throwing a plain Error is probably fine too!

Is there any chance I can get an update on this issue? It would be extremely useful to have a stack trace on errors thrown by postgrest-js for observability. Let me know if I can do anything to make it easier for maintainers!

@soedirgo @laurenceisla Please check this out. This is a huge issue for observability with a super simple fix. We currently can't trace DB errors down to a specific line. I have a PR up with tests.