Skip to content

Commit

Permalink
fix: shell.errorCode() honors shell.exit(code)
Browse files Browse the repository at this point in the history
This changes shell.exit() to use a wrapper function. This is so that
shell.errorCode() will have the correct error code after invoking
shell.exit(code). This isn't normally relevant, however a caller may be
listening for the exit status:

```
process.on('exit', code => {
  shell.exit(shell.errorCode());
});
```

Issue #1013
  • Loading branch information
nfischer committed Jul 16, 2023
1 parent 547a739 commit f7a7c75
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,20 @@ require('./commands').forEach(function (command) {
//@ ### exit(code)
//@
//@ Exits the current process with the given exit `code`.
exports.exit = process.exit;
exports.exit = function exit(code) {
if (code) {
common.error('exit', {
continue: true,
code: code,
prefix: '',
silent: true,
fatal: false,
});
process.exit(code);
} else {
process.exit();
}
};

//@include ./src/error.js
exports.error = require('./src/error');
Expand Down

0 comments on commit f7a7c75

Please sign in to comment.