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

Callback can be called twice #17

Open
eight04 opened this issue Dec 26, 2019 · 2 comments
Open

Callback can be called twice #17

eight04 opened this issue Dec 26, 2019 · 2 comments

Comments

@eight04
Copy link

eight04 commented Dec 26, 2019

delete-empty/index.js

Lines 60 to 61 in 6ae3454

.then(res => cb(null, res))
.catch(cb);

If cb() throws an error, it will be called again within the error object.

@doowb
Copy link
Collaborator

doowb commented Dec 27, 2019

Can you provide some example code with a case where this is causing a bug?

If so, a PR with a fix for the bug will be welcome.

@eight04
Copy link
Author

eight04 commented Dec 27, 2019

const deleteEmpty = require("delete-empty");

const path = ".";

const onDone = (err, result) => {
  console.log("onDone", err, result);
  throw new Error("error in onDone");
};

try {
  deleteEmpty(path, onDone);
} catch (err) {
  console.log("err", err);
}

onDone is called twice. REPL

The correct code should be:

.then(
    res => cb(null, res),
    err => cb(err, null) // or just `cb`
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants