pub struct CliError {
pub message: String,
pub code: u8,
}Expand description
A CLI failure carrying the exit code it maps to.
The two kinds encode the unified exit-code contract: CliError::usage → exit 2 (the user
invoked the tool wrong, e.g. an unknown or unsupported flag), CliError::runtime → exit 1
(the invocation was valid but the work failed). Success is the Ok arm, never a CliError.
Fields§
§message: StringHuman-readable message, printed to stderr as "<tool>: <message>".
code: u8The process exit code this error maps to (1 = runtime, 2 = usage).
Implementations§
Source§impl CliError
impl CliError
Sourcepub fn usage(message: impl Into<String>) -> Self
pub fn usage(message: impl Into<String>) -> Self
A usage error (exit 2): bad, unknown, or unsupported flags; missing operands.
Sourcepub fn runtime(message: impl Into<String>) -> Self
pub fn runtime(message: impl Into<String>) -> Self
A runtime error (exit 1): a valid invocation whose work failed.
Sourcepub fn unsupported(flag: impl Display) -> Self
pub fn unsupported(flag: impl Display) -> Self
An “unsupported flag” usage error (exit 2) with a consistent, greppable prefix.
Trait Implementations§
impl Eq for CliError
Source§impl Error for CliError
impl Error for CliError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
impl StructuralPartialEq for CliError
Auto Trait Implementations§
impl Freeze for CliError
impl RefUnwindSafe for CliError
impl Send for CliError
impl Sync for CliError
impl Unpin for CliError
impl UnsafeUnpin for CliError
impl UnwindSafe for CliError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more