How do I Get Error Stack rather than Digest on prod?
Unanswered
Dwarf Crocodile posted this in #help-forum
Dwarf CrocodileOP
Can't replicate the error on local at all. But on prod a page crashes and it's throwing a digest. How do I make it log the whole error? stack and all
16 Replies
Dwarf CrocodileOP
Bump?
Original message was deleted
Dwarf CrocodileOP
Ideally I want to understand how to control where these errors get posted and how they get handled. So a guide?
I can fix the error, when i find the trace
I can fix the error, when i find the trace
Greek Shepherd
Ive tried looking around for this as well and unless ur using some kind of error monitoring tool like sentry (which i can recommend anyway) it seems like you have to manually return custom objects instead of errors and display those.
Heres a good guide
https://medium.com/@keshav.aneja09/next-js-errors-be-like-i-exist-in-dev-but-disappear-in-production-2b4f1f4802f4
Heres a good guide
https://medium.com/@keshav.aneja09/next-js-errors-be-like-i-exist-in-dev-but-disappear-in-production-2b4f1f4802f4
@Greek Shepherd Ive tried looking around for this as well and unless ur using some kind of error monitoring tool like sentry (which i can recommend anyway) it seems like you have to manually return custom objects instead of errors and display those.
Heres a good guide
https://medium.com/@keshav.aneja09/next-js-errors-be-like-i-exist-in-dev-but-disappear-in-production-2b4f1f4802f4
Dwarf CrocodileOP
But my problem is that I don't even know how to reach the errors that get Digested.
I'm logging everything to stderr and storing that.
But some errors get thrown as a digest. No stack no nothing. So far I couldn't find any way to un-digest them, or even control them.
I'm logging everything to stderr and storing that.
But some errors get thrown as a digest. No stack no nothing. So far I couldn't find any way to un-digest them, or even control them.
Original message was deleted
Dwarf CrocodileOP
Please do, if you can 🙂 I couldn't find anything on it
@Dwarf Crocodile But my problem is that I don't even know how to reach the errors that get Digested.
I'm logging everything to stderr and storing that.
But some errors get thrown as a digest. No stack no nothing. So far I couldn't find any way to un-digest them, or even control them.
Greek Shepherd
ur error getting "thrown as a digest" just means its an uncaught error. the digest is a hash used to compare to server side logs. the reason u dont see it in production server side logs is because client components arent prerendered on the server. you need a logging tool like sentry to track those client errors.
u can go down every client component path on that page and check where errors could be thrown during render, and handle them using error boundaries
u can go down every client component path on that page and check where errors could be thrown during render, and handle them using error boundaries
@Greek Shepherd ur error getting "thrown as a digest" just means its an uncaught error. the digest is a hash used to compare to server side logs. the reason u dont see it in production server side logs is because client components arent prerendered on the server. you need a logging tool like sentry to track those client errors.
u can go down every client component path on that page and check where errors could be thrown during render, and handle them using error boundaries
Dwarf CrocodileOP
But I get the digest in the server logs. Not in the browser.
I have too many components to check, really.
⨯ [Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.] {
digest: 'DYNAMIC_SERVER_USAGE'I have too many components to check, really.
I get what the error is saying, but I want the stack trace of it to make debugging reasonable, ya know?
Greek Shepherd
ah i didnt realize it was a server component
@Dwarf Crocodile I get what the error is saying, but I want the stack trace of it to make debugging reasonable, ya know?
Greek Shepherd
thats just not possible i dont think. its still an uncaught error in those cases youll need to find where its coming from and catch them. then u can log
@Greek Shepherd thats just not possible i dont think. its still an uncaught error in those cases youll need to find where its coming from and catch them. then u can log
Dwarf CrocodileOP
That's the problem. Every other app gives you a stack trace of errors. Next swallows them for some reason.
Like, is there a way hijack their error handling?
Like, is there a way hijack their error handling?
@Dwarf Crocodile That's the problem. Every other app gives you a stack trace of errors. Next swallows them for some reason.
Like, is there a way hijack their error handling?
Greek Shepherd
yes using instrumentation. you really shouldnt DIY it tho. theres a reason nextjs obfuscates error messages in prod. i keep mentioning sentry just bc i dont know any other logging tools like it but.. sentry does the obfuscation for u while still allowing u to see the error messages and stack traces as well as a lot more info. they also use instrumentation
https://nextjs.org/docs/app/guides/instrumentation
https://nextjs.org/docs/app/guides/instrumentation
@Greek Shepherd yes using instrumentation. you really shouldnt DIY it tho. theres a reason nextjs obfuscates error messages in prod. i keep mentioning sentry just bc i dont know any other logging tools like it but.. sentry does the obfuscation for u while still allowing u to see the error messages and stack traces as well as a lot more info. they also use instrumentation
https://nextjs.org/docs/app/guides/instrumentation
Dwarf CrocodileOP
Ohhh, so I can get instrumentation to post errors into stderr?
Cos I'm not using sentry, jsut stderr and I'm analyzing them myself.
Cos I'm not using sentry, jsut stderr and I'm analyzing them myself.
@Dwarf Crocodile Ohhh, so I can get instrumentation to post errors into stderr?
Cos I'm not using sentry, jsut stderr and I'm analyzing them myself.
Greek Shepherd
again i dont think its a good idea but u do u
@Greek Shepherd again i dont think its a good idea but u do u
Dwarf CrocodileOP
why is it a bad idea?
Can't replicate the error on local at all. But on prod a page crashes and it's throwing a digest. How do I make it log the whole error? stack and allIts a bad idea because you might leak sensitive information from the server to the public. this includes giving a clue to attackers on how your systems are designed.
Ideally I want to understand how to control where these errors get posted and how they get handled. So a guide?Better to do server-side monitoring just like GetFookedLad said to monitor errors or monitor the error dirctly in the vercel "logs" tab.
But I get the digest in the server logs. Not in the browser.This is because you didnt caught the error that happens in the server component rendering. try doing as simple as
export default async function Page(){
try {
return ...
} catch (err) {
console.error(err)
return <></>
}
}to some of your server components