use assert_matches::assert_matches;
use error_fatality::{Fatality, Nested, Split};
use thiserror::Error;
#[derive(Debug, Error, Fatality, Split)]
enum Yikes {
#[fatal(true)]
#[error("An apple a day")]
Orange,
#[fatal(true)]
#[error("So dead")]
Dead,
}
fn so_dead() -> Result<[u8; 32], Yikes> {
Err(Yikes::Dead)
}
fn i_call_foo() -> Result<(), FatalYikes> {
let _x: Result<[u8; 32], JfyiYikes> = so_dead().into_nested()?;
unreachable!()
}
#[allow(clippy::print_stderr)]
fn i_call_foo_too() -> Result<(), FatalYikes> {
if let Err(should_be_fatal) = so_dead() {
eprintln!("You won't get here: {:?}", should_be_fatal.split()?);
} else {
unreachable!("`fn foo()` returns an error. qed");
}
unreachable!("Variant `Dead` is a `fatal` error. qed");
}
#[test]
fn test_i_call_foo_errors() {
assert_matches!(i_call_foo(), Err(_e));
}
#[test]
fn test_i_call_foo_too_errors() {
assert_matches!(i_call_foo_too(), Err(_e));
}