Skip to content
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

Add isNonzeroExitCode to Processes #725

Closed
sleberknight opened this issue Jun 2, 2022 · 1 comment · Fixed by #726
Closed

Add isNonzeroExitCode to Processes #725

sleberknight opened this issue Jun 2, 2022 · 1 comment · Fixed by #726
Assignees
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Milestone

Comments

@sleberknight
Copy link
Member

sleberknight commented Jun 2, 2022

Processes contains the isSuccessfulExitCode method which works well when you are checking the positive case:

if (Processes.isSuccessfulExitCode(exitCode)) {
  // handle success
}

But when checking the negative case it would not be too hard to miss the ! in front of Processes assuming you're not using a static import:

if (!Processes.isSuccessfulExitCode(exitCode)) {
  // handle a nonzero exit
}

This issue adds a new isNonzeroExitCode method to Processes to specifically indicate the exit code is nonzero, and not necessarily a failure or unsuccessful termination. For example, according to Exit Codes With Special Meanings in TLDP (The Linux Documentation Project), a code of 130 represents termination due to a user pressing CTRL+C. So, is that really a program failure or error? I would argue it's not necessarily a problem with the program, e.g. a user terminates a long-running command using CTRL+C instead of letting it finish normally. In Exit and Exit Status, TLDP also says:

A successful command returns a 0, while an unsuccessful one returns a non-zero value that usually can be interpreted as an error code.

The key word here is usually, leaving room for a nonzero exit code that isn't necessarily an error. So, using the generic isNonzeroExitCode seems like a decent and clear choice here.

So the above "negative" example will now become:

if (Processes.isNonzeroExitCode(exitCode)) {
  // handle a nonzero exit
}
@sleberknight sleberknight added the new feature A new feature such as a new class, method, package, group of classes, etc. label Jun 2, 2022
@sleberknight sleberknight added this to the 2.1.0 milestone Jun 2, 2022
@sleberknight sleberknight self-assigned this Jun 2, 2022
sleberknight added a commit that referenced this issue Jun 2, 2022
chrisrohr pushed a commit that referenced this issue Jun 2, 2022
* Add isNonzeroExitCode to Processes

Closes #725
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant