-
Notifications
You must be signed in to change notification settings - Fork 12.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
Support checking whether std::process::ExitCode
represents success or failure
#113081
Comments
the docs for exit code say this:
why do you want to introspect an exit code (instead of e.g. returning Result or an integer status from real_main)? |
as I see it, it would be very nice to be able to check this in tests.. |
Sorry for no update for long time... @jyn514 is right, we can resolve the case in my first post by introducing a custom type wrapping integer. However I'm not sure if it's desirable. I also realized that it's more problematic when we want to unit-test functions that returns Of course we can make those functions testable by replacing all usage of |
For my usecase I am building a CLI where each command returns an fn main() -> ExitCode {
let command = parse_cli_args();
switch command {
CommandFoo => command_foo(),
CommandBar => command_bar(),
// ...
}
} I was looking into how I might provide "meta commands" - commands that batch some commands together for DevX improvements. But I ofc don't want to run the next command if the previous command failed, eg fn command_combined() => ExitCode {
let result = command_foo();
if result != ExitCode::SUCCESS {
return result;
}
command_bar()
} But currently it looks like this is not possible - and instead I'll need to implement my own enum. |
IIUC there is no good way to check whether a
std::process::ExitCode
corresponds to success or failure. This is cumbersome, for example, when we want to check the exit code just before actually exiting.Can we add methods to
std::process::ExitCode
checking whether it is success or failure?It seems like
is_success
/is_failure
were considered when stabilizingstd::process::ExitCode
, but it was left as an unresolved question. #48711The text was updated successfully, but these errors were encountered: