-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Process::Status#exit_code
returns 0 on signal exit
#15228
Comments
Yes. I just think that ideally a solution to this would happen in the same release as #8647 This is for better awareness (a user might discover both changes at once when looking at the deprecation message for one of them) and to avoid recommending more usages of |
Raising an exception instead of undefined/invalid behavior and introducing a nilable version is 👍 |
The question about what consitutes a "normal exit" (#15231) and the quest for a portable definition also relates to |
This issue is derived from #8647 (review) but I figure it deserves a separate discussion from that PR and #8381 because it's a different issue.
Process::Status#exit_code
is supposed to return the exit code of a process. An exit code only exists when the process had a normal exit, though. On a signal exit, the value ofexit_code
would be undefined.However, currently, it returns
0
on a signal exit which is highly irritating.This could clearly mislead users who assume that
status.exit_code == 0
implies a succesful exit. Of course there is a dedicated methodProcess::Status#success?
for that and it operates correctly, but that's easy to overlook.It seems very wrong to report an exit code of
0
when the process did not even exit normally.And
status.success?
should be equivalent tostatus.exit_code.zero?
.The documentation does not specify any behaviour on a signal exit, it merely states:
I believe the best solution would be for
exit_code
to raise when the process did not exit normally.It might technically be preferable to return
nil
in this case, but that would break the method's signature.Raising does not it. It only affects behaviour. Still in a breaking way, but the current behaviour is clearly wrong. Code that depends on
exit_code == 0
on a signal exit depends on a bug.We could consider introducing
#exit_code?
as an alternative which does not raise but retrunnil
on signal exit.The text was updated successfully, but these errors were encountered: