Skip to content

Commit

Permalink
fix: handle exit(2) better
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Dec 29, 2017
1 parent 6333fa5 commit 5a914cb
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,6 @@ Nodemon is not perfect, and CLI arguments has sprawled beyond where I'm complete

See the [FAQ](https://github.com/remy/nodemon/blob/master/faq.md) and please add your own questions if you think they would help others.

## Contributors

This project exists thanks to all the people who [contribute](https://github.com/remy/nodemon/blob/master/.github/CONTRIBUTING.md).
[![nodemon contributors](https://opencollective.com/nodemon/contributors.svg?width=890)](https://opencollective.com/nodemon#backer)


## Backers

Thank you to all [our backers](https://opencollective.com/nodemon#backer)! 🙏
Expand Down
12 changes: 11 additions & 1 deletion faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ $ nodemon app.js -- -L -opt2 -opt3

nodemon will ignore all script arguments after `--` and pass them to your script.

# Error: "process failed, unhandled exit code (2)"

Nodemon will look for exit signals from the child process it runs. When the exit code is `2`, nodemon throws an error. Typically this is because the arguments are bad for the executing program, but it can also be due other reasons.

For example, mocha@3.x will exit with `2` on failing tests. To handle the exit code in a way that nodemon can consume, manually exit the process, i.e.:

```bash
nodemon -x 'mocha test/bad.test.js || exit 1'
```

# Can't install nodemon: permission issue

You may need to install nodemon using `sudo` (which isn't recommended, but I understand it's unavoidable in some environemnts). If the install fails with this appearing in the npm error log, then you need the following workaround.
Expand Down Expand Up @@ -103,7 +113,7 @@ A workaround is to make sure that `node` binary exists in the `PATH`:
sudo ln -s /usr/bin/nodejs /usr/local/bin/node
```

Alternatively the `--exec nodejs` option can be used.
Alternatively the `--exec nodejs` option can be used.

Fedora and Ubuntu pakage node as nodejs, because node.dpkg is

Expand Down
3 changes: 2 additions & 1 deletion lib/config/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ function exec(nodemonOptions, execMap) {

var options = utils.clone(nodemonOptions || {});

if (!options.script && options.args.length) { // try with the first argument
// if there's no script passed, try to get it from the first argument
if (!options.script && (options.args || []).length) {
const script = expandScript(options.args[0],
options.ext && ('.' + (options.ext || 'js').split(',')[0]));

Expand Down
3 changes: 1 addition & 2 deletions lib/monitor/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ function run(options) {

if (code === 2) {
// something wrong with parsed command
utils.log.error('failed to start process, possible issue with exec ' +
'arguments');
utils.log.error('process failed, unhandled exit code (2)');
bus.emit('error', code);
process.exit();
}
Expand Down
3 changes: 3 additions & 0 deletions lib/nodemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ function nodemon(settings) {
if (!config.required) {
const restartSignal = config.options.signal === 'SIGUSR2' ? 'SIGHUP' : 'SIGUSR2';
process.on(restartSignal, nodemon.restart);
utils.bus.on('error', () => {
utils.log.fail((new Error().stack));
});
utils.log.detail((config.options.restartable ? 'or ' : '') + 'send ' +
restartSignal + ' to ' + process.pid + ' to restart');
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"clean": "rm -rf test/fixtures/test*.js test/fixtures/test*.md",
"web": "node web",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"prepush": "npm run lint",
"postinstall": "node -e \"console.log('\\u001b[32mLove nodemon? You can now support the project via the open collective:\\u001b[22m\\u001b[39m\\n > \\u001b[96m\\u001b[1mhttps://opencollective.com/nodemon/donate\\u001b[0m\\n')\""
},
"devDependencies": {
Expand Down

0 comments on commit 5a914cb

Please sign in to comment.