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.

Throw error inside series callback

See original GitHub issue

What 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:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
aearlycommented, Jul 4, 2016

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.

0reactions
electeriouscommented, Jul 3, 2016

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 😕

Read more comments on GitHub >

github_iconTop 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 >

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