Skip to content

Commit

Permalink
Fix unhandledRejection on error inside function-based custom commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 committed Nov 22, 2024
1 parent 8f4a330 commit d7092d6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/api/_loaders/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,16 @@ class CommandLoader extends BaseCommandLoader {
})
.catch(err => {
if (instance instanceof EventEmitter) {
instance.emit('error', err);
if (instance.needsPromise) {
// if the instance has `needsPromise` set to `true`, the `error` event is listened
// on the `context` object, not on the `instance` object (in `treenode.js`).
this.emit('error', err);
} else {
// most probably a dead code because all `instance` objects with `EventEmitter`
// superclass are expected to be function-style commands which will always have
// the `needsPromise` property set to `true`. But, not taking chances here.
instance.emit('error', err);
}

return;
}
Expand Down

0 comments on commit d7092d6

Please sign in to comment.