Skip to content

Feature: Throw proper errors #3380

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

Open
shellscape opened this issue Feb 11, 2025 · 3 comments
Open

Feature: Throw proper errors #3380

shellscape opened this issue Feb 11, 2025 · 3 comments

Comments

@shellscape
Copy link

Current modern practice for the Node ecosystem is to inherit from Error and use the .code property to distinguish between errors. node-postgres does not. Like many today, we experienced an issue with Supabase downtime. And so we've started to look at how we can make our error handling in certain scenarios more robust.

Here's an example of how we currently have to track/check for errors:

.catch((err) => {
assert(err instanceof Error)
assert(/timeout expired\s*/.test(err.message))
closeServer(done)
})

Documentation for error.code https://nodejs.org/docs/v22.14.0/api/errors.html#errorcode

The error.code property is a string label that identifies the kind of error. error.code is the most stable way to identify an error. It will only change between major versions of Node.js. In contrast, error.message strings may change between any versions of Node.js.

At the least, it would be really nice to have canonical errors that we could easily look for and react to.

@brianc
Copy link
Owner

brianc commented Feb 11, 2025

Yup I dig the idea - interested in doing a PR? Only thing to note: if the database driver recieves an error from postgres directly it will have a .code on it already - that code comes from postgres. So in that case...you can use that code. I do see how the timeout errors and other things are hard to differentiate though!

@shellscape
Copy link
Author

Sweet. Yeah I can work this into my day job. Will try and get something in this week.

@brianc
Copy link
Owner

brianc commented Feb 12, 2025

Sweet. Yeah I can work this into my day job. Will try and get something in this week.

that would be awesome. :)

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

No branches or pull requests

2 participants