-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
process: make exitCode configurable again
#49579
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,17 +110,14 @@ if (process.argv[2] === undefined) { | |
|
|
||
| // Check process.exitCode | ||
| for (const arg of invalids) { | ||
| debug(`invaild code: ${inspect(arg.code)}`); | ||
| debug(`invalid code: ${inspect(arg.code)}`); | ||
| throws(() => (process.exitCode = arg.code), new RegExp(arg.pattern)); | ||
| } | ||
| for (const arg of valids) { | ||
| debug(`vaild code: ${inspect(arg.code)}`); | ||
| debug(`valid code: ${inspect(arg.code)}`); | ||
| process.exitCode = arg.code; | ||
| } | ||
|
|
||
| throws(() => { | ||
| delete process.exitCode; | ||
| }, /Cannot delete property 'exitCode' of #<process>/); | ||
| process.exitCode = 0; | ||
|
|
||
| // Check process.exit([code]) | ||
|
|
@@ -141,3 +138,10 @@ if (process.argv[2] === undefined) { | |
| process.exit(args[index].code); | ||
| } | ||
| } | ||
|
|
||
| const origExitCode = Object.getOwnPropertyDescriptor(process, 'exitCode'); | ||
| try { | ||
| delete process.exitCode; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should just test that redefining |
||
| } finally { | ||
| Object.defineProperty(process, 'exitCode', origExitCode); | ||
| } | ||
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.
I think it needs to be handled so that even when users delete
process.exitCode, the exit code set by the core code will still be applied.process.exitCodeis also used by the core. This is concerning because if users delete it, the intended behavior in the core, like the code mentioned above (#49579 (comment)), won't be applied.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.
I'm not sure how that would be possible. If it's deleted, there's nothing there.
Uh oh!
There was an error while loading. Please reload this page.
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.
Do note that
process.exitCode = kGenericUserError;will still work after it's been deleted, it just won't have the magic getter/setter anymore.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.
If
process.exitCode = kGenericUserError;worked, the error code after terminating the node should bekGenericUserError, not 0. Last time I checked, it was 0... right?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.
I mean it should not be 0 when calling the exit status.
echo $?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.
it can be restricted to any domain you like :-) just integer numbers then?
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.
I'm not sure I can give you the answer you want, as I can't guess how you'd implement it based on your current description. Currently, the types allowed are:
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.
ok, so I’ll move forward with that schema, thanks.
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.
hmm - seems like the exitCode is read in C++, so i'm not sure how it can read the JS-set value once it's overridden.
@daeyeon are you comfortable with this proceeding with the understanding that if a user mocks process.exitCode, it's up to them to restore it? (just like other globals)
If not, what about #49579 (comment) ?
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.
The core's behavior related to exitCode will be breaking during the time gap between mocking and restoring. It's probably not enough to rely on the restoring after finishing the mocking.
Looks like a good idea. In addition to moving the getters/setters to the process prototype, I think that the core code should use the exitCode of the process prototype, rather than the process itself. This would address concerns about breaking and can provide guidance on how users can monitor it.