-
Notifications
You must be signed in to change notification settings - Fork 18
Dealing with process exit codes #22
Comments
Some ideas: The generic member access RFC makes it so we can extract exit codes from arbitrary errors if they provide one. If we updated Something like this: #[unstable(feature = "termination_trait_lib", issue = "43301")]
impl<E: std::error::Error> Termination for Result<!, E> {
fn report(self) -> i32 {
let Err(err) = self;
eprintln!("Error: {:?}", err);
let exit_code = err.context::<&ExitCode>().unwrap_or(&ExitCode::FAILURE);
exit_code.report()
}
} Even if we don't update the std Until |
I suggested up #20 largely because it'd make rust's handling of numeric exit codes far more POSIX like but more flexible. If created from a a numeric error code, then a It could then later be promoted to allocation based types that track the backtrace, etc., maybe one could even make this promotion depend upon a alloc feature, but the point is largely to make smaller rust crates more usable when doing things like writing an OS. I actually noticed that #20 would be useful from seeing zcash's crypto libs use the |
Makes sense and good to know
fwiw, I think this is also true of |
The idea is the tinybox crate would have an alloc feature. If the alloc feature is enabled then it invokes box for types with alignment or size larger than |
There are two sides to this
Turning
std::process::Command
into errorsProviding a way to bubble up process exit codes to main
std::process::Command
s exit code to bubble up, sometimes they won'tstd::io::ErrorKind
to bubble up and sometimes they won'tAlternative:
std::process::exit
throughout the business logic. Personally, I've found unexpected forms of exiting a program to lead to "spaghetti code".Exit code prior art:
std::process::ExitCode
sysexit
std::process::Command
s andstd::io::ErrorKind
s to codesexit-code
andexitcode
i32
constantsproc-exit
std::process::Command
s andstd::io::ErrorKind
s to codesmain
prior art:std::process::Termination
Debug
intoDisplay
forTermination
traitproc-exit
Debug
intoDisplay
if choosing to rely onTermination
traitTermination
, provides a way to get custom exit codes to the userThe text was updated successfully, but these errors were encountered: