-
Notifications
You must be signed in to change notification settings - Fork 14
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
Exit codes #20
Exit codes #20
Conversation
I think the main thing I'd like to see here is separating out the following cases:
I would divide them up into three categories:
|
WRT Let me do some thinking and I'll try to update the RFC later today. |
Apologies for the delay! I finally had some time to work on this and have expanded and partially rewritten the RFC. |
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.
This is awesome work, and I think I agree with basically all of it so far. I think we should go ahead and merge this RFC (unless you want to make any final minor revisions based on comments). It's still early enough that we can optimistically merge RFCs and implement them, and write followup RFCs if the design changes after we learn more from experience.
|
||
## Implementation | ||
|
||
Exit codes shall be defined as an `enum` with appropriate documentation comments and an explicit integer value for each element. Being explicit about values allows simple, at-a-glance correlation of exit codes to error types (as well as enabling sparse values). |
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.
This is a really, really great idea. 👍
[unresolved]: #unresolved-questions | ||
|
||
- Is a process needed for 'vetting' new exit codes, to prevent duplication? If so, is the RFC process appropriate? Alternatively, is code review sufficient? | ||
- Should we engage npm/Yarn to improve error categorization (either through parsable output or diversifying exit codes)? |
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.
Yarn does have the ability to generate JSON formatted output, although currently you have to choose one or the other. I have reached out to some folks involved with Yarn to see if it'd be possible to "tee" the output via a config file or environment variable, so that a developer could choose whatever output they want at stdout/stderr, but we could specify a side file that also receives the output in JSON format.
text/0000-exit-codes.md
Outdated
|
||
## Shims | ||
|
||
Of the three "first-class" shims (`node`, `npm`, and `yarn`), only Node currently publishes a [list of exit codes](https://nodejs.org/api/process.html#process_exit_codes); the other two only emit codes 0/1 for success/failure. The exit codes for other shimmed executables is too large a space to examine, but Node follows what appears to be a common practice: simply numbering errors starting with 1, preserving the [special meanings commonly applied by POSIX shells](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_02). This gives us incentive to avoid low-numbered exit codes (as likely to conflict) and exit codes with the high bit set (as typically representing termination due to signals). |
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.
Don't forget npx
, too.
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.
Is npx
a first-class shim (i.e. does it have special handling attached to it)? I had thought it was being handled as a "generic" 3rd-party shim.
Oh, one more thing: it looks like you've done (very thorough!) research on Unix/POSIX signals, but what about Windows conventions for exit codes? |
|
||
Of the three "first-class" shims (`node`, `npm`, and `yarn`), only Node currently publishes a [list of exit codes](https://nodejs.org/api/process.html#process_exit_codes); the other two only emit codes 0/1 for success/failure. The exit codes for other shimmed executables is too large a space to examine, but Node follows what appears to be a common practice: simply numbering errors starting with 1, preserving the [special meanings commonly applied by POSIX shells](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_02). This gives us incentive to avoid low-numbered exit codes (as likely to conflict) and exit codes with the high bit set (as typically representing termination due to signals). | ||
|
||
Additionally, shims must do their utmost to preserve the exit code supplied by the shimmed executable, only introducing a shim-specific exit code if the executable cannot be run at all. To this end, shims must return 0 when the shimmed executable does, even if the shim itself is not able to perform its work (for example, if a new shim cannot be created when installing a new executable via `npm` or `yarn`). |
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.
Really insightful point. With the idea of pushing harder on statelessness, some of these tricky edge cases may get simpler—for example, I think in the end we won't actually need npm i -g
/yarn global add
/etc to create shims. Generally, a more stateless model has fewer opportunities to fail, since it doesn't make as many persistent changes to the filesystem.
I added a section addressing Windows exit codes and why I'm not proposing compatibility with them. |
This is looking great and looks ready to merge to me. If no one raises any issues in the next couple days I'll merge it. |
Rendered