Enum docopt::Error [−][src]
Represents the different types of Docopt errors.
This error type has a lot of variants. In the common case, you probably
don’t care why Docopt has failed, and would rather just quit the program
and show an error message instead. The exit
method defined on the Error
type will do just that. It will also set the exit code appropriately
(no error for --help
or --version
, but an error code for bad usage,
bad argv, no match or bad decode).
Example
Generally, you want to parse the usage string, try to match the argv and then quit the program if there was an error reported at any point in that process. This can be achieved like so:
use docopt::Docopt; const USAGE: &'static str = " Usage: ... "; let args = Docopt::new(USAGE) .and_then(|d| d.parse()) .unwrap_or_else(|e| e.exit());
Variants
Usage(String)
Parsing the usage string failed.
This error can only be triggered by the programmer, i.e., the writer of the Docopt usage string. This error is usually indicative of a bug in your program.
Argv(String)
Parsing the argv specified failed.
The payload is a string describing why the arguments provided could not be parsed.
This is distinct from NoMatch
because it will catch errors like
using flags that aren’t defined in the usage string.
The given argv parsed successfully, but it did not match any example usage of the program.
Regrettably, there is no descriptive message describing why the given argv didn’t match any of the usage strings.
Deserialize(String)
This indicates a problem deserializing a successful argv match into a deserializable value.
Parsing failed, and the program usage should be printed next to the
failure message. Typically this wraps Argv
and NoMatch
errors.
Decoding or parsing failed because the command line specified that the help message should be printed.
Version(String)
Decoding or parsing failed because the command line specified that the version should be printed
The version is included as a payload to this variant.
Implementations
impl Error
[src]
pub fn fatal(&self) -> bool
[src]
Return whether this was a fatal error or not.
Non-fatal errors include requests to print the help or version information of a program, while fatal errors include those such as failing to decode or parse.
pub fn exit(&self) -> !
[src]
Print this error and immediately exit the program.
If the error is non-fatal (e.g., Help
or Version
), then the
error is printed to stdout and the exit status will be 0
. Otherwise,
when the error is fatal, the error is printed to stderr and the
exit status will be 1
.
Trait Implementations
impl Debug for Error
[src]
impl Display for Error
[src]
impl Error for Error
[src]
fn source(&self) -> Option<&(dyn StdError + 'static)>
[src]
pub fn backtrace(&self) -> Option<&Backtrace>
[src]
pub fn description(&self) -> &str
1.0.0[src]
pub fn cause(&self) -> Option<&dyn Error>
1.0.0[src]
impl Error for Error
[src]
fn custom<T: Display>(msg: T) -> Self
[src]
pub fn invalid_type(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self
[src]
pub fn invalid_value(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self
[src]
pub fn invalid_length(len: usize, exp: &dyn Expected) -> Self
[src]
pub fn unknown_variant(variant: &str, expected: &'static [&'static str]) -> Self
[src]
pub fn unknown_field(field: &str, expected: &'static [&'static str]) -> Self
[src]
pub fn missing_field(field: &'static str) -> Self
[src]
pub fn duplicate_field(field: &'static str) -> Self
[src]
Auto Trait Implementations
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnwindSafe for Error
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,