Skip to content

Commit 5a914cb

Browse files
committed
fix: handle exit(2) better
1 parent 6333fa5 commit 5a914cb

File tree

6 files changed

+18
-10
lines changed

6 files changed

+18
-10
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,6 @@ Nodemon is not perfect, and CLI arguments has sprawled beyond where I'm complete
324324

325325
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.
326326

327-
## Contributors
328-
329-
This project exists thanks to all the people who [contribute](https://github.com/remy/nodemon/blob/master/.github/CONTRIBUTING.md).
330-
[![nodemon contributors](https://opencollective.com/nodemon/contributors.svg?width=890)](https://opencollective.com/nodemon#backer)
331-
332-
333327
## Backers
334328

335329
Thank you to all [our backers](https://opencollective.com/nodemon#backer)! 🙏

faq.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ $ nodemon app.js -- -L -opt2 -opt3
2626

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

29+
# Error: "process failed, unhandled exit code (2)"
30+
31+
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.
32+
33+
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.:
34+
35+
```bash
36+
nodemon -x 'mocha test/bad.test.js || exit 1'
37+
```
38+
2939
# Can't install nodemon: permission issue
3040

3141
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.
@@ -103,7 +113,7 @@ A workaround is to make sure that `node` binary exists in the `PATH`:
103113
sudo ln -s /usr/bin/nodejs /usr/local/bin/node
104114
```
105115

106-
Alternatively the `--exec nodejs` option can be used.
116+
Alternatively the `--exec nodejs` option can be used.
107117

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

lib/config/exec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ function exec(nodemonOptions, execMap) {
7575

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

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

lib/monitor/run.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ function run(options) {
143143

144144
if (code === 2) {
145145
// something wrong with parsed command
146-
utils.log.error('failed to start process, possible issue with exec ' +
147-
'arguments');
146+
utils.log.error('process failed, unhandled exit code (2)');
148147
bus.emit('error', code);
149148
process.exit();
150149
}

lib/nodemon.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ function nodemon(settings) {
138138
if (!config.required) {
139139
const restartSignal = config.options.signal === 'SIGUSR2' ? 'SIGHUP' : 'SIGUSR2';
140140
process.on(restartSignal, nodemon.restart);
141+
utils.bus.on('error', () => {
142+
utils.log.fail((new Error().stack));
143+
});
141144
utils.log.detail((config.options.restartable ? 'or ' : '') + 'send ' +
142145
restartSignal + ' to ' + process.pid + ' to restart');
143146
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"clean": "rm -rf test/fixtures/test*.js test/fixtures/test*.md",
3838
"web": "node web",
3939
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
40+
"prepush": "npm run lint",
4041
"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')\""
4142
},
4243
"devDependencies": {

0 commit comments

Comments
 (0)