logo
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: ErrorKind

Deprecated, replaced with Error::kind()

info: Vec<String>

Deprecated, replaced with Error::context()

Implementations

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.

Format the existing message with the Command’s context

Type of error for programmatic processing

Additional information to further qualify the error

Should the message be written to stdout or not?

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.

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

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

The lower-level source of this error, if any. Read more

🔬 This is a nightly-only experimental API. (backtrace)

Returns a stack backtrace, if available, of where this error occurred. Read more

👎 Deprecated since 1.42.0:

use the Display impl or to_string()

👎 Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Converts to this type from the input type.

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.