Skip to content
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

Merged

Conversation

jkieboom
Copy link
Contributor

Fixes #1416.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 26, 2022

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:

Sandbox Source
MSW React Configuration

@@ -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,
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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)

Copy link
Member

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!

@jkieboom jkieboom force-pushed the feature/uncaught-exception-error-stack branch from 15ab6a1 to 33484d3 Compare September 26, 2022 13:37
@kettanaito kettanaito changed the title feat: include error stack in log when handling uncaught exceptions fix: include error stack in log when handling uncaught exceptions Oct 1, 2022
Copy link
Member

@kettanaito kettanaito left a 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 🎉

@kettanaito kettanaito merged commit 933a9d6 into mswjs:main Oct 1, 2022
@kettanaito
Copy link
Member

Released: v0.47.4 🎉

This has been released in v0.47.4!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants