1 unstable release
0.1.0 | Jul 15, 2022 |
---|
#30 in #open-file
7KB
119 lines
uerr
uerr
is a crate which provides stunning visual error handling.
Showcase
Using the code below, we can display a simple error and show it to the user.
use uerr::UserError;
#[test]
fn sample_error() {
UserError::from("could not open file")
.and_reason("The system cannot find the file specified.")
.and_help("Does this file exist?")
.print_all("uerr/error: ");
}
Output
uerr/error: could not open file
- caused by: The system cannot find the file specified.
+ help: Does this file exist?
With multiple arguments
program.exe: could not open file
- caused by: The system cannot find the file specified.
| Filler reason.
+ help: Does this file exist?
| Filler help.
Click to see the code.
#[test]
fn sample_error() {
UserError::from("could not open file")
.and_reason("The system cannot find the file specified.")
.and_reason("Filler reason.")
.and_help("Does this file exist?")
.and_help("Filler help.")
.print_all("program.exe: ");
}
Exiting with errors
The UserError
struct also supports inline exiting.
#[test]
fn sample_error() {
UserError::from("Sample Error")
.print_all("my program: ")
.exit(-1);
}