mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 13:07:46 +00:00
uucore/error: add macros for standardized error handling
This commit is contained in:
parent
66b1ac019d
commit
43bfec7170
1 changed files with 18 additions and 0 deletions
|
@ -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.
|
/// Show an error to stderr in a similar style to GNU coreutils.
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! show_error(
|
macro_rules! show_error(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue