delete-empty icon indicating copy to clipboard operation
delete-empty copied to clipboard

Callback can be called twice

Open eight04 opened this issue 6 years ago • 2 comments

https://github.com/jonschlinkert/delete-empty/blob/6ae34547663e6845c3c98b184c606fa90ef79c0a/index.js#L60-L61

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

eight04 avatar Dec 26 '19 20:12 eight04

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.

doowb avatar Dec 27 '19 16:12 doowb

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`
)

eight04 avatar Dec 27 '19 18:12 eight04