-
-
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
Exit Code is Zero if Subcommand Killed by Signal #2021
Comments
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Yes, I agree. Edit: actually, should be using the code argument from the |
Ah right, calling
I am not sure using same signal in parent is an appropriate response in all cases. (Although it would probably reproduce the eventual exit status.)
The only portable way I found to map signal names to signal numbers is However, my understanding after some research is that the external "exit code" for a signal may be more complicated than what the program can achieve by calling For example: "When a command terminates on a fatal signal whose number is N, Bash uses the value 128+N as the exit status."
I think this would be simpler to implement, and simpler to predict behaviour.
Morally I am not sure if there is an underlying exit code at this point, and in particular this is explicit in what |
The related
https://nodejs.org/dist/latest-v18.x/docs/api/child_process.html#event-exit |
Fair points. With this issue I'm concerned about two things, in order of importance:
A fixed exit code will address 1, which is good, but does not address 2. You're right that bubbling up the signal to the parent process may not be appropriate in certain corner cases, but it does address 2 in that you get some indication of what caused the subcommand to exit. A fixed exit code wouldn't be as much of a concern if there was a debug log or something (which I don't believe commander has) which could contain the extra information to address 2, but without one, I don't think a fixed exit code can resolve 2. Given the existing constraints, there may not be a way to address 2, unfortunately. |
Thanks @dsanders11 I opened draft #2023. Does not have unit tests yet, and I'll leave it draft for a couple of days in case we have any fresh ideas about signal number. |
Released in Commander v12.0.0. |
If a subcommand child process is killed by a signal (e.g.
SIGKILL
), then commander will exit with exit code zero. I'm seeing this where OOM was killing the subcommand but commander was exiting with zero.Relevant code looks to be here. The arguments to the
close
event are(code, signal)
and in the case of killed by signal,code
will benull
, soprocess.exit
gets called withnull
which leads to exiting with zero. Additionally, should theexitCallback
case (on line 1036) be usingproc.exitCode
instead ofprocess.exitCode
? The latter doesn't seem correct.commander.js/lib/command.js
Lines 1032 to 1038 in 4ef19fa
Possible fix for the issue could be to bubble up signals, although I'm not sure how to handle the
exitCallback
case then, since AFAIK there's no way to get an exit code for a signal from Node.js (other than mapping it yourself).Alternatively a fixed exit code of 1 could be used in the case of a signal, which would work for the
exitCallback
case. However, that's not desirable since it will hide the underlying exit code from the subcommand.Manually mapping signals to exit codes might be the simplest way to handle this for both cases.
The text was updated successfully, but these errors were encountered: