Struct clap::Error[][src]

pub struct Error {
    pub kind: ErrorKind,
    pub info: Vec<String>,
    // some fields omitted
}
Expand description

Command Line Argument Parser Error

See App::error to create an error.

Fields

kind: ErrorKind

The type of error

info: Vec<String>

Additional information depending on the error kind, like values and argument names. Useful when you want to render an error of your own.

Implementations

Create an unformatted error

This is for you need to pass the error up to a place that has access to the App at which point you can call Error::format]. Prefer [App::error` for generating errors.

Format the existing message with the App’s context

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 1 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::App;

match App::new("App").try_get_matches() {
    Ok(matches) => {
        // do_something
    },
    Err(err) => {
        err.print().expect("Error writing Error");
        // do_something
    },
};
👎 Deprecated since 3.0.0:

Replaced with App::error

Deprecated, replaced with App::error

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

Performs the conversion.

Performs the conversion.

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

Performs the conversion.

Performs the conversion.

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.