1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 04:27:45 +00:00

uucore/error: add macros for standardized error handling

This commit is contained in:
Terts Diepraam 2021-06-28 13:39:34 +02:00
parent 66b1ac019d
commit 43bfec7170

View file

@ -21,6 +21,24 @@ macro_rules! executable(
})
);
#[macro_export]
macro_rules! show(
($err:expr) => ({
let e = $err;
uucore::error::set_exit_code(e.code());
eprintln!("{}: {}", executable!(), e);
})
);
#[macro_export]
macro_rules! show_if_err(
($res:expr) => ({
if let Err(e) = $res {
show!(e);
}
})
);
/// Show an error to stderr in a similar style to GNU coreutils.
#[macro_export]
macro_rules! show_error(