-
Notifications
You must be signed in to change notification settings - Fork 275
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
Better error reporting. Add original query and params to the thrown exception. #17
Comments
Yes, that's a very good point.
|
What about |
Haha :) Literally just tested that, and it seems good :)
|
@porsager please don't keep it to yourself :) |
Hehe, no worries @davojan ... I wouldn't, I just simply haven't had time to wrap it up and get it out.. I should manage to get this in during this week though :) And thanks a lot for the offer to help, this one is pretty straight forward, but I'll be sure to reach out for anything I can think of. |
Ok, it's on master now... Would be great if you could give it a shot @davojan ? :) |
Thanks! I've tried this, works like a charm! |
Ah right, I forgot to test that.. I initially thought it wouldn't be that bad because I'm not accessing the stack trace unless there's an error. I'm just attaching an I just tested by caching the error using the tagged array instead, and then there's no performance hit at all, but it does mean that the stack trace will be of the code path which called the query first. That is a bit misleading, so maybe cut off the rest of the stack that can be wrong by default, and then have an option to enable full stack traces which will mean worse performance. What do you think? And thanks for thinking ahead ! ;) |
I think the best and simplest thing for now is to leave stack trace capturing as is (because it's very useful) but wrap the code with Next step is to investigate - why node's native async stack traces (which are now enabled by default) doesn't work with this library, and maybe modify code to fix that. |
Ok, I've been on a little hunt, and it seems that support for async stack traces doesn't work with Promise as used in Postgres.js. There should be work underway to make it work which can be tracked here: Eg. not even something simple as this will work: async function run() {
await new Promise((resolve, reject) => {
setTimeout(() =>
reject(new Error('wat'))
, 200)
})
}
run().catch(console.error) // bad stack trace I think it's still worth it to use the cached method and always include a single line from userland code since it's way better than nothing in production. Then we can add support for long stack traces through a debug flag or a stackTraceLimit option. We could even allow single queries to store long stack traces with a special method. |
Currently db exception looks like this:
There are two problems here:
Stack trace doesn't tell anything about my own source code. Although async stack trace is enabled in node 12. May be node's socket API doesn't support async stack traces. It seems to be hard problem to solve and may be out of the scope of the library. But it should be considered.
There is technical information from postgres server included, but no useful info about original query and params. I would be great if the query and params will be manually injected into the Error object before thrown to the app code.
The text was updated successfully, but these errors were encountered: