Support Javascript Error.cause stacktrace unrolling / visualisation
See original GitHub issueDescription
Our project uses error wrapping extensively to provide more fine-grained user experiences depending on what type of error occurred, and what the context was. When wrapping an error we use the new Error options.cause
to retain the original Error object:
try {
await aRiskyManuever();
} catch (e) {
throw new ManueverFailedError('it was not a success', { cause: e });
}
// full original Error with stacktrace will now be available in `error.cause`
This “official” way of wrapping an error is now supported in Chrome and node v16
(the current LTS).
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error
Describe the solution you’d like
It would be really useful if the Bugsnag stacktrace view somehow supported showing the stacktrace from each error in the cause
chain (since an error can be wrapped multiple times).
As it stands, we only get to see the stacktrace/context around the final error that was thrown.
Describe alternatives you’ve considered
I believe there is a slightly hacky workaround available, that involves manually concatenating the stacktrace from each error in the chain into a single string that follows the “normal” stacktrace format. We could potentially try and do this in our own error handling system before the error hits the Bugsnag notify
call.
I’ll probably be looking into this in the short term, but I didn’t want that to stop me requesting what I think would be a useful feature for Bugsnag moving into the future, as this is an “official” way that JS errors can be structured.
Additional context
node.js compatibility for Error.cause
: https://node.green/#ES2022-features-Error-cause-property
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top GitHub Comments
Glad to hear it. I have updated my code snippet with your addition for the benefit of future travelers. Thanks again for bringing our attention to
Error.cause
. It’s something I’m sure we’d like to bake into the JS notifier automatically at some point, as priorities allow.Hi all - we added support for
Error.cause
inv7.17.0
🎉