Stack trace on constraint failed doesn't include my application code
I'm just getting started using drizzle on a new app, with sqlite and nuxt 3.
Everything has been great, but there's one thing happening that really concerns me: when I generate an insert that fails a NOT NULL constraint, I get an error, but the stack trace doesn't include my application code. This is worrying me, because how would I find the issue if my app was large?
Is it normal for drizzle stack traces to not include the calling function in the stack trace? If not, any suggestions how I go about fixing this?
Example: because my code is small, I know this error was generated by
server/utils/drizzle.ts
at line 80 in the function selectOrCreateSession
:
Is this expected? How would I debug this if I end up with a LARGE drizzle app?
I've tried starting nuxt with: NODE_OPTIONS='--trace-uncaught' nuxt dev
, because yeah, general node issue, but no luck.5 Replies
I don't have the answer, so I will be following along. But I am curious, are you using prepared statements by any chance?
No prepared statements, although using them is one of my next ideas. Do you ever see this issue, or is this particular to me?
I haven't had this before, no. But usually this happens because it's being cut off by how the async chain is being handled.
So maybe you have a return statement somewhere before awaiting a promise? So you have a chain that finishes before your context is done.
If not, maybe drizzle does. If also not that, some other reason the context is severed. Otherwise I am out of ideas sorry đ
Yeah, I suspected the async chain too, I always get a little confused at this point lol. That's why I hoped --trace-uncaught would change things, but no luck.
I'm seeing this in another context too, I'm wondering if something nuxt is doing is making this more likely to happen.
something nuxt is doing or something I'm doing wrong with nuxt I should say lol
Here's a "minimal repro" example with nuxt 3, maybe this will inspire somebody:
If I comment out the with(), everything works, its a valid query. The with just makes the query invalid, and it results in a stack trace without the application code in the stack like:
In contrast, throwing an async error inside a nuxt 3 event handler doesn't normally result in a "disconnected" stack trace, for example:
Results in the connected stack trace (note the first line references server/api/session[id].get.ts):
I donât know whatâs going on with âdefineEventHandlerâ. Iâm on my phone so itâs hard to read. But event handlers, especially async ones, are easily detached. Could that be the issue?