(function() {var type_impls = { "clap_builder":[["
source§

impl<F: ErrorFormatter> Debug for Error<F>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
","Debug","clap_builder::Error"],["
source§

impl<F: ErrorFormatter> Display for Error<F>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
","Display","clap_builder::Error"],["
source§

impl<F: ErrorFormatter> Error<F>

source

pub fn raw(kind: ErrorKind, message: impl Display) -> Self

Create an unformatted error

\n

This is for you need to pass the error up to\na place that has access to the Command at which point you can call Error::format.

\n

Prefer Command::error for generating errors.

\n
source

pub fn format(self, cmd: &mut Command) -> Self

Format the existing message with the Command’s context

\n
source

pub fn new(kind: ErrorKind) -> Self

Create an error with a pre-defined message

\n

See also

\n\n
§Example
\n
\nlet cmd = clap::Command::new(\"prog\");\n\nlet mut err = clap::Error::new(ErrorKind::ValueValidation)\n    .with_cmd(&cmd);\nerr.insert(ContextKind::InvalidArg, ContextValue::String(\"--foo\".to_owned()));\nerr.insert(ContextKind::InvalidValue, ContextValue::String(\"bar\".to_owned()));\n\nerr.print();
\n
source

pub fn with_cmd(self, cmd: &Command) -> Self

Apply Command’s formatting to the error

\n

Generally, this is used with Error::new

\n
source

pub fn apply<EF: ErrorFormatter>(self) -> Error<EF>

Apply an alternative formatter to the error

\n
§Example
\n
let cmd = Command::new(\"foo\")\n    .arg(Arg::new(\"input\").required(true));\nlet matches = cmd\n    .try_get_matches_from([\"foo\", \"input.txt\"])\n    .map_err(|e| e.apply::<KindFormatter>())\n    .unwrap_or_else(|e| e.exit());
\n
source

pub fn kind(&self) -> ErrorKind

Type of error for programmatic processing

\n
source

pub fn context(&self) -> impl Iterator<Item = (ContextKind, &ContextValue)>

Additional information to further qualify the error

\n
source

pub fn get(&self, kind: ContextKind) -> Option<&ContextValue>

Lookup a piece of context

\n
source

pub fn insert(\n &mut self,\n kind: ContextKind,\n value: ContextValue,\n) -> Option<ContextValue>

Insert a piece of context

\n
source

pub fn use_stderr(&self) -> bool

Should the message be written to stdout or not?

\n
source

pub fn exit_code(&self) -> i32

Returns the exit code that .exit will exit the process with.

\n

When the error’s kind would print to stderr this returns 2,\nelse it returns 0.

\n
source

pub fn exit(&self) -> !

Prints the error and exits.

\n

Depending on the error kind, this either prints to stderr and exits with a status of 2\nor prints to stdout and exits with a status of 0.

\n
source

pub fn print(&self) -> Result<()>

Prints formatted and colored error to stdout or stderr according to its error kind

\n
§Example
\n
use clap::Command;\n\nmatch Command::new(\"Command\").try_get_matches() {\n    Ok(matches) => {\n        // do_something\n    },\n    Err(err) => {\n        err.print().expect(\"Error writing Error\");\n        // do_something\n    },\n};
\n
source

pub fn render(&self) -> StyledStr

Render the error message to a StyledStr.

\n
§Example
\n
use clap::Command;\n\nmatch Command::new(\"Command\").try_get_matches() {\n    Ok(matches) => {\n        // do_something\n    },\n    Err(err) => {\n        let err = err.render();\n        println!(\"{err}\");\n        // do_something\n    },\n};
\n
",0,"clap_builder::Error"],["
source§

impl<F: ErrorFormatter> Error for Error<F>

source§

fn source(&self) -> Option<&(dyn Error + 'static)>

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

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type based access to context intended for error reports. Read more
","Error","clap_builder::Error"],["
source§

impl<F: ErrorFormatter> From<Error> for Error<F>

source§

fn from(e: Error) -> Self

Converts to this type from the input type.
","From","clap_builder::Error"],["
source§

impl<F: ErrorFormatter> From<Error> for Error<F>

source§

fn from(e: Error) -> Self

Converts to this type from the input type.
","From","clap_builder::Error"]] };if (window.register_type_impls) {window.register_type_impls(type_impls);} else {window.pending_type_impls = type_impls;}})()