Crate my_pretty_failure
source ·Expand description
my-pretty-failure
my-pretty-failure display failure (and context) in an elegant way
Example n°1
With defaut option
ⓘ
extern crate my_pretty_failure;
use my_pretty_failure::myprettyfailure;
fn main() {
let err = err1().unwrap_err(); // your failure
println!("{}", myprettyfailure(&err)); // or panic!
}
console output
🔥 error
---------------------------------------------------------
a long err1
---------------------------------------------------------
▶ caused by: a very long err2
▶ caused by: an another deep err3
---------------------------------------------------------
Example n°2
With your options
ⓘ
extern crate my_pretty_failure;
use my_pretty_failure::{myprettyfailure_option, MyPrettyFailurePrint};
extern crate yansi; // or ansi_term, colored ...
fn main() {
let err = err1().unwrap_err(); // your failure
println!("{}", myprettyfailure_option(MyPrettyFailurePrint {
head: format!("🔔 my pretty app catch an {}", yansi::Paint::red("error")),
separator: "- - - - - - - - - - - - - - - - - - -".to_string(),
causedby: "context".to_string(),
}, &err));
}
console output
🔔 my pretty app catch an error
- - - - - - - - - - - - - - - - - - -
a long err1
- - - - - - - - - - - - - - - - - - -
▶ context: a very long err2
▶ context: an another deep err3
- - - - - - - - - - - - - - - - - - -