add error_and_panic helper for logerr
This commit is contained in:
parent
3e6a944df8
commit
21adbec2ce
|
@ -2,6 +2,14 @@ use std::{error::Error, fmt::Debug};
|
|||
|
||||
use log::{debug, error};
|
||||
|
||||
// So we still get a useful panic when logs are filtered
|
||||
macro_rules! error_and_panic {
|
||||
($($arg:tt)*) => {
|
||||
log::error!($($arg)*);
|
||||
panic!($($arg)*);
|
||||
};
|
||||
}
|
||||
|
||||
pub trait UnwrapLog {
|
||||
type Target;
|
||||
|
||||
|
@ -35,8 +43,7 @@ where
|
|||
match self {
|
||||
Ok(target) => target,
|
||||
Err(err) => {
|
||||
error!("called `Result::unwrap_log()` on an `Err` value: {err}");
|
||||
panic!("called `Result::unwrap_log()` on an `Err` value: {err}");
|
||||
error_and_panic!("called `Result::unwrap_log()` on an `Err` value: {err}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,8 +52,9 @@ where
|
|||
match self {
|
||||
Ok(target) => target,
|
||||
Err(err) => {
|
||||
error!("[{expect}] called `Result::expect_log()` on an `Err` value: {err}");
|
||||
panic!("[{expect}] called `Result::expect_log()` on an `Err` value: {err}");
|
||||
error_and_panic!(
|
||||
"[{expect}] called `Result::expect_log()` on an `Err` value: {err}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,8 +84,7 @@ where
|
|||
match self {
|
||||
Some(target) => target,
|
||||
None => {
|
||||
error!("called `Option::unwrap_log()` on a `None` value");
|
||||
panic!("called `Option::unwrap_log()` on a `None` value");
|
||||
error_and_panic!("called `Option::unwrap_log()` on a `None` value");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,8 +93,7 @@ where
|
|||
match self {
|
||||
Some(target) => target,
|
||||
None => {
|
||||
error!("[{expect}] called `Option::expect_log()` on an `None` value");
|
||||
panic!("[{expect}] called `Option::expect_log()` on an `None` value");
|
||||
error_and_panic!("[{expect}] called `Option::expect_log()` on an `None` value");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue