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
fix: include error stack in log when handling uncaught exceptions #1417
fix: include error stack in log when handling uncaught exceptions #1417
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit a4564c2:
|
@@ -105,7 +105,7 @@ export const createRequestListener = ( | |||
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/recipes/mocking-error-responses`, | |||
request.method, | |||
request.url, | |||
error, | |||
error.stack ?? error, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this not print the error
if its stack exists?
I thought we may add a new console.error(error)
call below this devUtils.error()
to forward the error to the console. What do you think about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prints the error (which will just be name + message) if the stack is undefined. The stack actually also includes the name and message already. Not sure about console.error
vs devUtils.error
. You have to tell me what is more appropriate. For me it fits will with displaying the error directly within this message and not as a separate disconnected thing on another log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, so the issue was that at some point there are errors that don't have a stack
? And those were somehow ignored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No the issue is that Error.toString()
only includes the name
and message
, never the stack
. Per spec, stack
on Error
is optional, so it's best to guard against it being undefined
(although I don't know when this could happen in practice)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thanks for the explanation!
15ab6a1
to
33484d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for making MSW better, @jkieboom! Welcome to contributors 🎉
Released: v0.47.4 🎉This has been released in v0.47.4! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
Fixes #1416.