pg-mem icon indicating copy to clipboard operation
pg-mem copied to clipboard

Include PSQL Error Codes in Execution Errors

Open josh-feldman opened this issue 4 years ago • 3 comments

Some business logic may revolve around the type of PSQL execution error that gets thrown during a query. Libs like node-postgres return the PSQL error code on the error in a field code on the error itself. To match the functionality of those libraries, would it be possible to include the appropriate error code on execution errors thrown via this library?

josh-feldman avatar Apr 02 '21 18:04 josh-feldman

That could be possible. Actually, I recently began including error messages matching actual pg errors + some details that pg usually provides.

See here for an example

I could also include the error code with that.

That said, most throw new QueryError statements currently only include an error message, and there are A LOT of them... so it would mean finding the corresponding errors for a lot of different errors... so even if its easy to implement (virtually anyone could do it), that is quite a bit of work, in the end.

oguimbal avatar Apr 02 '21 22:04 oguimbal

I just planned to update the error for unique_violation. Looking at your examples, what is the easiest way to get error, details, hint? or do I have to see what pg returns?

clemens-smartparking avatar May 19 '21 21:05 clemens-smartparking

Yes, you must try against an actual postgres database to know what is returned :/

oguimbal avatar May 19 '21 21:05 oguimbal