Struct cargo_edit::CliError
source · Expand description
The CLI error is the error type used at Cargo’s CLI-layer.
All errors from the lib side of Cargo will get wrapped with this error. Other errors (such as command-line argument validation) will create this directly.
Fields§
§error: Option<Error>The error to display. This can be None in rare cases to exit with a
code without displaying a message. For example cargo run -q where
the resulting process exits with a nonzero code (on Windows), or an
external subcommand that exits nonzero (we assume it printed its own
message).
exit_code: i32The process exit code.
Implementations§
source§impl CliError
impl CliError
sourcepub fn new(error: Error, code: i32) -> CliError
pub fn new(error: Error, code: i32) -> CliError
Attach an error code to an error
Examples found in repository?
src/errors.rs (line 51)
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
fn from(err: anyhow::Error) -> CliError {
CliError::new(err, 101)
}
}
impl From<clap::Error> for CliError {
fn from(err: clap::Error) -> CliError {
#[allow(clippy::bool_to_int_with_if)]
let code = if err.use_stderr() { 1 } else { 0 };
CliError::new(err.into(), code)
}
}
impl From<std::io::Error> for CliError {
fn from(err: std::io::Error) -> CliError {
CliError::new(err.into(), 1)
}