Throw error inside series callback
See original GitHub issueWhat version of async are you using?
2.0.0-rc.6
Which environment did the issue occur in (Node version/browser version)
v6.2.0
What did you do? Please include a minimal reproducable case illustrating issue.
I’m trying to throw an error inside the series callback, but the error gets caught for some reason.
The following works fine:
throw new Error('throw_0') // => Node stops here
async.series([
(next) => clean(distPath, next),
(next) => copy(routes, srcPath, distPath, opts, next),
(next) => run(routes, srcPath, distPath, next)
], (err) => {
throw new Error('throw_1')
})
While throwing an error inside the series callback doesn’t.
// throw new Error('throw_0')
async.series([
(next) => clean(distPath, next),
(next) => copy(routes, srcPath, distPath, opts, next),
(next) => run(routes, srcPath, distPath, next)
], (err) => {
throw new Error('throw_1') // Node stops here, but the error gets caught somehow and never shows up
})
What was the actual result?
Node continues to execute. No error visible.
What did you expect to happen?
I expect that the error gets thrown and my node app crashes because of throw_1
.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5
Top Results From Across the Web
How to throw an error inside of a call back, and catch it outside
function, inside the anonymous function, I am throwing an error which gets caught inside of the second catch block. Then I am throwing...
Read more >How To Handle Errors in Asynchronous Javascript Code ...
The first argument of the callback is usually named error, whereby if something goes wrong in the asynchronous function, then the callback gets ......
Read more >Why asynchronous exceptions are uncatchable with callbacks
Throwing an error asynchronously means that an error is thrown in the JavaScript code of an asynchronously executed callback. Throwing exception asynchronously.
Read more >Futures and error handling | Dart
The following example deals with throwing an exception from within then() 's callback and demonstrates catchError() 's versatility as an error handler:.
Read more >Errors | Node.js v19.3.0 Documentation
Throwing an error inside the callback can crash the Node.js process in most cases. ... the MyError // frame would show up in...
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
Yeah, a promise would catch any errors in the callstack – including in the callbacks. You can defer calling the callback (e.g.
setImmediate(callback, null, results)
) to work around that.I’ve found the problem. There’s a promise deeply hidden in the
run
function. Somehow—and I’ve no idea why—catches all the errors, even those thrown in the async.series callback 😕