pub struct Error {
pub kind: ErrorKind,
pub info: Vec<String>,
/* private fields */
}Expand description
Command Line Argument Parser Error
See Command::error to create an error.
Fields§
§kind: ErrorKindDeprecated, replaced with Error::kind()
info: Vec<String>Deprecated, replaced with Error::context()
Implementations§
Source§impl Error
impl Error
Sourcepub fn raw(kind: ErrorKind, message: impl Display) -> Error
pub fn raw(kind: ErrorKind, message: impl Display) -> Error
Create an unformatted error
This is for you need to pass the error up to
a place that has access to the Command at which point you can call Error::format.
Prefer Command::error for generating errors.
Sourcepub fn format(self, cmd: &mut App<'_>) -> Error
pub fn format(self, cmd: &mut App<'_>) -> Error
Format the existing message with the Command’s context
Sourcepub fn context(&self) -> impl Iterator<Item = (ContextKind, &ContextValue)>
pub fn context(&self) -> impl Iterator<Item = (ContextKind, &ContextValue)>
Additional information to further qualify the error
Sourcepub fn use_stderr(&self) -> bool
pub fn use_stderr(&self) -> bool
Should the message be written to stdout or not?
Sourcepub fn exit(&self) -> !
pub fn exit(&self) -> !
Prints the error and exits.
Depending on the error kind, this either prints to stderr and exits with a status of 2
or prints to stdout and exits with a status of 0.
Sourcepub fn print(&self) -> Result<(), Error>
pub fn print(&self) -> Result<(), Error>
Prints formatted and colored error to stdout or stderr according to its error kind
§Example
use clap::Command;
match Command::new("Command").try_get_matches() {
Ok(matches) => {
// do_something
},
Err(err) => {
err.print().expect("Error writing Error");
// do_something
},
};Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()