Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

process: use exit 1 for uncaughtException #6191

Merged
merged 2 commits into from Sep 7, 2013

Conversation

isaacs
Copy link

@isaacs isaacs commented Sep 7, 2013

Since it is Unix tradition to use exit code 1 for general-purpose script
bail-out, and the way of doing that in Node is to throw an exception and
not catch it, it makes the most sense to exit with 1 when an exception
goes uncaught.

Move the Invalid Argument exit to 9, so that it's something specific,
and clear that it's a node internal error.

Also, document the exit codes that we use.

Respect numeric string args to process.exit(code)
Since it is Unix tradition to use exit code 1 for general-purpose script
bail-out, and the way of doing that in Node is to throw an exception and
not catch it, it makes the most sense to exit with 1 when an exception
goes uncaught.

Move the `Invalid Argument` exit to 9, so that it's something specific,
and clear that it's a node internal error.

Also, document the exit codes that we use.
@isaacs isaacs merged commit b30a03e into nodejs:master Sep 7, 2013
`SIGKILL` or `SIGHUP`, then its exit code will be `128` plus the
value of the signal code. This is a standard Unix practice, since
exit codes are defined to be 7-bit integers, and signal exits set
the high-order bit, and then contain the value of the signal code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you've already closed this PR but do you intend to document all the various internal exit codes? I suspect that most people won't care and besides, there's nothing stopping a script from exiting with e.g. exit code 4. Just the exit code is not enough to determine what really happened.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, not closed but merged... the point stands though, documenting internal error codes seems mostly pointless to me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, users can use internal error codes, and that can confuse things. But that's kind of always been a problem with exit codes in general (ie, any program can exit with 3 or 127, even though bash reserves those.) Still, if we're going to use them for debugging at all (and they ARE occasionally very handy) then I think we probably ought to document them.

I see what you're saying though, and I sort of agreed (which is why I didn't document them when I introduced them somewhat haphazardly in 0.10, actually), but @tjfontaine convinced me of the error of my ways.

I'm not at all married to the specific semantics, of course. I just changed all the exit(1) calls once upon a time based on the order in which they appeared in the code. Documenting them made me realize that we could probably sort them more logically. But, meh. I think the important thing is that "generic, unspecified, userland-triggered exit" is exit code 1 (rather than 8), and that the others are documented somewhere. Also, this isn't the best place for it. We probably ought to have a "command line" section in the docs. Maybe this and the command-line args could be moved under the "Synopsis" section?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants