| Crates.io | cmd_error |
| lib.rs | cmd_error |
| version | 1.0.0 |
| created_at | 2022-12-13 23:56:56.832303+00 |
| updated_at | 2022-12-13 23:56:56.832303+00 |
| description | Simple crate to print an error message and exit while unwrapping Options and Results |
| homepage | |
| repository | https://github.com/AlexanderHarrison/cmd_error |
| max_upload_size | |
| id | 736214 |
| size | 15,033 |
When unwrapping Options and Results it's oddly
annoying to print a simple error message and exit.
This crate introduces the ErrExit trait which allows exactly that.
For example,
use cmd_error::ErrExit;
fn main() {
let path = std::env::args().nth(1)
.unwrap_exit("file path not passed");
let file = std::fs::read_to_string(&path)
.unwrap_exit(&format!("file {} not found", path));
// ...
}
Why not use expect?
Panic message aren't for users, they're for the programmers.
This crate also exports the function print_err_and_exit
which unsurprisingly prints an error message and exits.
Exits with an exit code of 1. Errors are printed to stderr.