Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callbacks called twice when containing errors #32

Closed
jspri opened this issue Nov 3, 2016 · 0 comments
Closed

Callbacks called twice when containing errors #32

jspri opened this issue Nov 3, 2016 · 0 comments
Assignees
Labels

Comments

@jspri
Copy link

jspri commented Nov 3, 2016

When the callback provided to batch.end throws an error things can go a bit haywire... Here is an example I put together.

const Batch = require('batch')
const batch = new Batch()

batch.push(cb => cb())
batch.push(cb => cb())
batch.push(cb => cb())

var i = 1;

batch.end(function(err) {
  console.log(i++)

  if(err) {
    console.log(err)
  }

  throw "Error"
})

Outputs

1
2
Error

This shows the callback being called twice, once with no error (expected) and once with the error contained in the callback! After doing a bit of digging I found the try/catch block in index.js:117 to be the culprit. I assume this was put in so that synchronous type functions would produce callback style errors. It's a really messy bug to have though because it can catch all downstream errors of the callback.

jspri added a commit to jspri/batch that referenced this issue Nov 3, 2016
@dougwilson dougwilson self-assigned this Mar 25, 2017
@dougwilson dougwilson added the bug label Mar 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants