Skip to content

Errors are missing stack trace #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
meyer9 opened this issue Nov 9, 2023 · 2 comments
Closed
2 tasks done

Errors are missing stack trace #501

meyer9 opened this issue Nov 9, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@meyer9
Copy link
Contributor

meyer9 commented Nov 9, 2023

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/[email protected]';

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!

@meyer9 meyer9 added the bug Something isn't working label Nov 9, 2023
@meyer9
Copy link
Contributor Author

meyer9 commented Nov 26, 2023

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!

@meyer9
Copy link
Contributor Author

meyer9 commented Jan 10, 2024

@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.

@meyer9 meyer9 closed this as completed Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant