Errors in rejected promises not handled
See original GitHub issueHi I’m not sure if this is expected or not but we have errors happening inside a try/catch in a promise where the catch rejects the promise with the caught error. Chrome shows these as errors in the dev console, but Bugsnag doesn’t seem to get them.
I put together a JS fiddle with bugsnag loaded in to demonstrate the error: https://jsfiddle.net/zz050pg4/2/ . If you just put in your bugsnag api key on the first line, you can see that it notifies correctly for errors outside the promise. The promise code below is in a library and is basically:
var errPromise = new Promise(function (resolve, reject) {
try {
// call some of our source code to cause error
} catch (err) {
reject(err);
}
})
Any thoughts?
Issue Analytics
- State:
- Created 8 years ago
- Comments:6
Top Results From Across the Web
What is an unhandled promise rejection? - Stack Overflow
A rejected promise is like an exception that bubbles up towards the application entry point and causes the root error handler to produce...
Read more >Error handling with promises - The Modern JavaScript Tutorial
In case of an error, the promise becomes rejected, and the execution should jump to the closest rejection handler. But there is none....
Read more >Tracking Unhandled Promise Rejections - TrackJS
When a promise is rejected, it looks for a rejection handler. If it finds one, like in the example above, it calls the...
Read more >Handling those unhandled promise rejections with JS async ...
In the first case, the key is this part of the error message: … by rejecting a promise which was not handled with...
Read more >What is UnhandledPromiseRejectionWarning
catch(). A rejected promise is like an exception that bubbles up towards the application entry point and causes the root error handler to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I agree. There is no reason why the notifier cannot hook into the
unhandledrejection
event.I will submit a PR
this eveningsoon, unless anybody wants to beat me to it - or has any other ideas.You’re most welcome 😃
This is because you are catching the errors yourself. Promises automatically reject if a thrown error is uncaught. If you need the caught error to be passed to Bugsnag, I would recommend doing something along the lines of…
or, better yet…
It turns out that
Bugsnag.notifyException
is compatible with promises, because the first argument accepts anError
, and promises only pass one argument tothen
andcatch
.