1 个不稳定版本
0.1.0 | 2022年7月15日 |
---|
#14 in #file-exists
7KB
119 行代码,不包括注释
uerr
uerr
是一个提供惊人的可视化错误处理的 crate。
展示
使用以下代码,我们可以显示一个简单的错误并将其展示给用户。
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: ");
}
输出
uerr/error: could not open file
- caused by: The system cannot find the file specified.
+ help: Does this file exist?
带有多个参数
program.exe: could not open file
- caused by: The system cannot find the file specified.
| Filler reason.
+ help: Does this file exist?
| Filler help.
点击查看代码。
#[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: ");
}
带有错误退出
UserError
结构体也支持内联退出。
#[test]
fn sample_error() {
UserError::from("Sample Error")
.print_all("my program: ")
.exit(-1);
}