Skip to content

Commit

Permalink
fix: smarter handling of exit code 2
Browse files Browse the repository at this point in the history
Only exit after code 2 if it happened quickly; improve messaging (recommend `||exit 1`)

If nodemon exits _quickly_ on code 2, then it'll bail and warn. If it's after ~500ms, then it assumes that the sub-process intentionally used exit 2 (like mocha or stylelint), it won't bail and treat it as a failure (like a crash).

Props to @joeytwiddle

Fixes #496 
Fixes #627
  • Loading branch information
joeytwiddle authored and remy committed Jul 17, 2018
1 parent 363891f commit 11ef298
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/monitor/run.js
Expand Up @@ -158,9 +158,22 @@ function run(options) {
process.exit();
}

if (code === 2) {
// something wrong with parsed command
// If the command failed with code 2, it may or may not be a syntax error
// See: http://git.io/fNOAR
// We will only assume a parse error, if the child failed quickly
if (code === 2 && Date.now() < config.lastStarted + 500) {
utils.log.error('process failed, unhandled exit code (2)');
utils.log.error('');
utils.log.error('Either the command has a syntax error,');
utils.log.error('or it is exiting with reserved code 2.');
utils.log.error('');
utils.log.error('To keep nodemon running even after a code 2,');
utils.log.error('add this to the end of your command: || exit 1');
utils.log.error('');
utils.log.error('Read more here: https://git.io/fNOAG');
utils.log.error('');
utils.log.error('nodemon will stop now so that you can fix the command.');
utils.log.error('');
bus.emit('error', code);
process.exit();
}
Expand Down

0 comments on commit 11ef298

Please sign in to comment.