Closed BppleMan closed 1 year ago
If anyone needs to get any fields or function calls from the original error, they can use downcast_ref
fn fun1(condition: bool) -> color_eyre::Result<(), Report> {
if condition {
Err(MyError::MyPanic("this is MyPanic".to_string()).into())
} else {
Err(MyError::OtherPanic("this is OtherPanic".to_string()).into())
}
}
fn fun2() -> color_eyre::Result<()> {
fun1(true)
}
fn fun3(condition: bool) -> color_eyre::Result<()> {
match fun1(condition) {
Ok(_) => Ok(()),
Err(e) => {
match e.downcast_ref().unwrap() {
MyError::MyPanic(s) => {
println!("MyPanic: {:#?} is catched. then will return Ok", &e);
Ok(())
},
_ => {
println!("not catched");
Err(e)
},
}
}
}
}
Is there some trait that allows me to obtain the reporter's ability after implementation?
I defined an enum error with thiserrror: