question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support Javascript Error.cause stacktrace unrolling / visualisation

See original GitHub issue

Description

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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
djskinnercommented, Jan 27, 2022

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.

1reaction
luke-beltoncommented, Jun 21, 2022

Hi all - we added support for Error.cause in v7.17.0 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript's try-catch hid my bugs! - freeCodeCamp
When errors are caught and not handled properly they are lost. That 'bubbling up' process happens only up until the error encounters a...
Read more >
Stack Trace for JavaScript Error - AppDynamics Community
I can see the details of Error like Script Origin, Line No. and Message. But can't find the stack Trace information in the...
Read more >
A Definitive Guide to Handling Errors in JavaScript - Kinsta
TypeError stack trace in a browser. This is because, at the time of rendering, the state container is undefined; thus, there exists no...
Read more >
Performance hit of newing up Error object in modern Node.js
I built a benchmark test and posted it to my github repo. The results of my tests confirms that the V8 engine behind...
Read more >
JavaScript errors page: Detect and analyze errors
Go to one.newrelic.com > Browser > (select an app) > JS errors. Use the available options in the UI to examine what may...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found