pub enum ErrorKind {
UnsupportedArgument {
argument: Box<str>,
},
UnsupportedSwitch {
switch: Box<str>,
},
MissingSwitchArgument {
switch: Box<str>,
argument: &'static str,
},
MissingPositional {
name: &'static str,
},
MissingRequired {
name: &'static str,
reason: Option<&'static str>,
},
InputError {
error: InputError,
},
Error {
name: Box<str>,
error: Box<dyn Error + Send + Sync + 'static>,
},
}
Expand description
The kind of an error.
Variants
UnsupportedArgument
Encountered an argument that was not supported.
An unsupported argument is triggered when none of the branches in the parser matches the current agument.
Examples
argwerk::define! {
struct Args { }
// This errors because `bar` is not a supported switch, nor do we
// match any positional arguments.
["--file", arg] => {}
}
let error = Args::parse(vec!["bar"]).unwrap_err();
assert!(matches!(error.kind(), argwerk::ErrorKind::UnsupportedArgument { .. }));
UnsupportedSwitch
Encountered a switch that was not supported.
An unsupported switch is caused by the same reason as an unsupported
argument, but it’s prefixed with a hyphen -
.
Examples
argwerk::define! {
#[usage = "command [-h]"]
struct Args { }
// This errors because `--path` is not a supported switch. But
// `"--file"` is.
["--file", arg] => {}
}
let error = Args::parse(vec!["--path"]).unwrap_err();
assert!(matches!(error.kind(), argwerk::ErrorKind::UnsupportedSwitch { .. }));
MissingSwitchArgument
Fields
argument: &'static str
The argument that was missing, like path
in --file <path>
.
When a parameter to an argument is missing.
Examples
argwerk::define! {
struct Args { }
// This errors because `--file` requires an argument `path`, but
// that is not provided.
["--file", path] => {}
}
let error = Args::parse(vec!["--file"]).unwrap_err();
assert!(matches!(error.kind(), argwerk::ErrorKind::MissingSwitchArgument { .. }));
MissingPositional
Fields
name: &'static str
The name of the argument missing like path
in <path>
.
When a positional argument is missing.
Examples
argwerk::define! {
struct Args { }
// This errors because `b` is a required argument, but we only have
// one which matches `a`.
[a, b] => {}
}
let error = Args::parse(vec!["foo"]).unwrap_err();
assert!(matches!(error.kind(), argwerk::ErrorKind::MissingPositional { .. }));
MissingRequired
Fields
name: &'static str
The name of the required variable that is missing.
When a positional argument is missing.
Examples
argwerk::define! {
struct Args {
#[required = "--name must be used"]
name: String,
}
["--name", n] => {
name = Some(n);
}
[rest] => {}
}
let error = Args::parse(vec!["foo"]).unwrap_err();
assert!(matches!(error.kind(), argwerk::ErrorKind::MissingRequired { name: "name", .. }));
InputError
Fields
error: InputError
The underlying error.
Failed to parse input as unicode string.
This is raised in case argwerk needs to treat an input as a string, but that is not possible.
This is required if the string needs to be used in a switch branch.
Error
Fields
When an error has been raised while processing an argument, typically when something is being parsed.
Examples
argwerk::define! {
#[usage = "command [-h]"]
struct Args { }
// This errors because we raise an error in the branch body.
["foo"] => {
Err("something went wrong")
}
}
let error = Args::parse(vec!["foo"]).unwrap_err();
assert!(matches!(error.kind(), argwerk::ErrorKind::Error { .. }));
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for ErrorKind
impl Send for ErrorKind
impl Sync for ErrorKind
impl Unpin for ErrorKind
impl !UnwindSafe for ErrorKind
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more