-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Smarter handling of exit code 2 #1381
Conversation
I'm not convinced this is the right change. I think the messaging in the exit should be clearer, but that's all. With your changes, here is the workflow:
Since the actual exec command is wrong, the developer has to Automatically restarting on file changes will never make that command work. I think the right change is to update the error message that's shown, perhaps linking to the FAQ (which can be added to with links and even more context). I can't see a reason for nodemon not to exit on code 2 - unless I'm missing something? |
The argument not to exit on code 2 is that mocha will sometimes exit with code 1, 2, 3, 4, ... (and stylelint too), and usually in those cases we still want Currently behaviour with mocha is somewhat inconsistent. On the other hand, yes sometimes code 2 means you wrote a bad shell command. And in that case exiting nodemon is slightly preferable. So I guess we have to decide which is more bothersome: nodemon stops running mocha tests unexpectedly, or having to hit Ctrl-C after typing a bad command. Anyway I do agree, in either case, some messaging may help to guide the developer. I will look into that. Other options:
I would like to look into 1b, and situational messaging. |
f6114b5
to
32bf6f3
Compare
OK, I have changed the behaviour:
To test, try: ./bin/nodemon.js -x 'ls <'
# exits with logging
# Now simulate mocha failing with two tests
./bin/nodemon.js -x 'sleep 1 ; exit 2'
# nodemon keeps running Possible concerns:
|
0727813
to
88fa65b
Compare
lib/monitor/run.js
Outdated
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: || true'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add: Read more here: https://git.io/fNOAG
after line 169.
Two comments I've left, and once these are in, I'm happy with the PR - thank you and great work 👍 |
Remy, I only saw one comment from you! I have added the link to the FAQ as you asked. But what was the second comment? I have taken a guess, and changed the Thank you for |
My apologies. I probably made a rebase/amend and a force push yesterday, just after you commented, so the comment got lost. I have added a code comment with the If you want to make adjustments to this branch directly, I will not be offended. 🙇♂️ |
I've never really known how do that cleanly. Once I clone the branch locally, (from past experience) I couldn't push back into the PR and had to make my own branch and new PR - really odd. Anyway, this looks good - thanks! |
This PR removes the special handling of exit code 2.
Not only
mocha
but alsostylelint
will sometimes exit with code 2, resulting in unexpected behaviour from nodemon. (It exits, and stops monitoring.)The
|| true
workaround is unusual and easy to forget. I only ever remember to add it after I have been bitten!If there is no special reason to keep the special handling of code 2, then I think it would be best to remove it.
(In the case when a developer does provide a non-parseable command, which exits with code 2, an error is already reported to the console. So we won't be keeping developers in the dark by not quitting. After this PR, the developer will need to hit Ctrl-C to exit nodemon, in order to fix their command. For an example syntax error, try:
nodemon -x 'ls <'
)Fixes #496 #627
This could perhaps be part of a major release, just in case some people are using it as a way to break out of nodemon intentionally: #751 (comment)