#[macro_export]
macro_rules! format_err {
($kind:expr, $msg:expr) => {
$kind.context($crate::error::Message::new($msg))
};
($kind:expr, $fmt:expr, $($arg:tt)+) => {
format_err!($kind, &format!($fmt, $($arg)+))
};
}
#[macro_export]
macro_rules! fail {
($kind:expr, $msg:expr) => {
return Err(format_err!($kind, $msg).into())
};
($kind:expr, $fmt:expr, $($arg:tt)+) => {
fail!($kind, &format!($fmt, $($arg)+))
};
}
#[macro_export]
macro_rules! ensure {
($cond:expr, $kind:expr, $msg:expr) => {
if !($cond) {
return Err(format_err!($kind, $msg).into());
}
};
($cond:expr, $kind:expr, $fmt:expr, $($arg:tt)+) => {
ensure!($cond, $kind, format!($fmt, $($arg)+))
};
}
#[macro_export]
macro_rules! fatal {
($app:expr, $msg:expr) => {
$crate::application::exit::fatal_error($app, $crate::error::Message::new($msg))
};
($app:expr, $fmt:expr, $($arg:tt)+) => {
fatal!($app, format!($fmt, $($arg:tt)+))
};
}