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

Custom exit code handling #313

Closed
adamralph opened this issue Jun 12, 2021 · 1 comment · Fixed by #315
Closed

Custom exit code handling #313

adamralph opened this issue Jun 12, 2021 · 1 comment · Fixed by #315
Labels
breaking This change could break current consumers enhancement New feature or request
Milestone

Comments

@adamralph
Copy link
Owner

adamralph commented Jun 12, 2021

Use case(s)

Some commands return non-zero exit codes when they succeed. For example, Robocopy:

An Exit Code of 0-7 is success and any value >= 8 indicates that there was at least one failure during the copy operation.

When running such a command, the default exit code handling in SimpleExec may throw an exception when the command succeeds. Custom exit code handling is required for these scenarios.

Description

Run, RunAsync, Read, and ReadAsync have a new optional parameter: Func<int, bool> handleExit. The supplied delegate argument should return true to indicate that it handled the exit code, and that the default exit code handling in SimpleExec should be suppressed, and false otherwise.

For example:

Run("robocopy", handleExitCode: exitCode => exitCode < 8);

Breaking, because handleExitCode was added as an optional parameter before cancellationToken in RunAsync and ReadAsync.

Also deprecates NonZeroExitCodeException in favour of ExitCodeException, since the name of the former doesn't make sense when an argument is supplied to handleExitCode.

Alternatives

Catch and swallow the exception in consuming code when the exit code indicates success.

Additional context

Replaces #298. Thanks to @nixtar for raising that issue.

Depends on #311.

@adamralph adamralph added the enhancement New feature or request label Jun 12, 2021
@adamralph adamralph added this to the 7.1.0 milestone Jun 12, 2021
@adamralph adamralph added the breaking This change could break current consumers label Jun 12, 2021
@adamralph
Copy link
Owner Author

@nixtar I've released this in 8.0.0-alpha.1 if you want to give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change could break current consumers enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant