-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
The Book should document, and use, the idiomatic way to exit unsuccessfully without panicing #38300
Comments
fn main() {
::std::process::exit(match run_your_app() {
Ok(0) => 1, // no matches
Ok(_) => 0, // some matches
Err(someerr) => {
report(someerr); 2 // return whatever you want depending on the error
}
});
} |
@nagisa That's reasonably tidy, and I can see how it's safe in a single-threaded program (everything needing destroying must have been destroyed by the time |
|
The book is no longer being actively developed; we're working on the second edition over here: https://github.com/rust-lang/book Would you mind opening an issue on that repo? I'm not totally convinced that this belongs in the book, but let's talk about it over there. |
I think this is about more than just the book. The docs for |
We already have a ticket for that: #29370 |
main
in a Rust program returns no value, AFAICT (I can't find any reference documentation formain
, but all the examples just dofn main() {
). All of the examples in The Book either panic or exit normally (even in error cases), and process exit statuses are not mentioned anywhere. This is Wrong. The Book should document the idiomatic way to exit unsuccessfully without panicing, and all of the example programs should use that method when appropriate.Take for instance this example from https://doc.rust-lang.org/book/error-handling.html#parsing-integers:
The
Err
case inmain
should cause the program to exit unsuccessfully, but without panicing.Related, I can't figure out what the idiomatic way to exit unsuccessfully without panicing actually is. The only thing I've found is
std::process::exit
, whose documentation makes it sound like it is not the correct thing to use (e.g. dire warnings about not running destructors).The basic
grep
exit-status convention should be mentioned at some point (code 0 = no error, matches found; code 1 = no error, no matches found; code 2 = error occurred).The text was updated successfully, but these errors were encountered: