Skip to main content

UsageErr

Enum UsageErr 

Source
#[non_exhaustive]
pub enum UsageErr {
Show 28 variants InvalidFlag { token: String, reason: String, span: SourceSpan, input: String, }, MissingFlag(String), DuplicateFlag(String), MissingGroup { group: String, members: String, }, InvalidInput(String, SourceSpan, NamedSource<String>), MissingArg(String), MissingSubcommand(String, String), ArgRequiresDoubleDash(String), Help(String), Version(String), Miette(MietteError), IO(Error), Strum(ParseError), FromUtf8Error(FromUtf8Error), TeraError(Error), KdlError(KdlError), FileError(Error, PathBuf), ShellError(String), VarArgTooFew { name: String, min: usize, got: usize, }, VarArgTooMany { name: String, max: usize, got: usize, }, VarFlagTooFew { name: String, min: usize, got: usize, }, VarFlagTooMany { name: String, max: usize, got: usize, }, InvalidPath(String), InvalidView(String), InvalidOutput(String), InvalidValue { name: String, value: String, reason: String, }, UnsupportedShell(String), MissingMountOutput(String),
}
Expand description

Everything that can go wrong reading a spec or a command line against one.

#[non_exhaustive], so a caller matching on it needs a _ arm. That is the point: this enum grows every time the spec learns to say something new — MissingGroup arrived with groups, ArgRequiresDoubleDash with double_dash — and without this each one is a major release for everyone downstream.

With the miette feature enabled, this implements miette::Diagnostic so applications can pass it directly to their existing miette reporter. The feature is disabled by default.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

InvalidFlag

Fields

§token: String
§reason: String
§input: String
§

MissingFlag(String)

§

DuplicateFlag(String)

§

MissingGroup

A required group had none of its members given.

Its own variant rather than a UsageErr::MissingFlag holding a sentence, because there is no one flag to name: the group is the thing that was not satisfied, and a caller that renders errors itself needs the members as members.

Fields

§group: String
§members: String
§

InvalidInput(String, SourceSpan, NamedSource<String>)

§

MissingArg(String)

§

MissingSubcommand(String, String)

A command that declares subcommand_required was given none.

The spec could say this and the parser did not read it, so mise generate — which declares it — parsed as though it were a complete invocation. usage-argv and clap both refuse it.

§

ArgRequiresDoubleDash(String)

§

Help(String)

§

Version(String)

§

Miette(MietteError)

§

IO(Error)

§

Strum(ParseError)

§

FromUtf8Error(FromUtf8Error)

§

TeraError(Error)

§

KdlError(KdlError)

§

FileError(Error, PathBuf)

A file the spec model was asked to read could not be read.

Carries the path as well as the io error: “No such file or directory” on its own names nothing, and this is reported for spec files given on a command line.

§

ShellError(String)

A run= script could not be run, exited non-zero, or produced output usage could not read. The message names the shell and the script.

§

VarArgTooFew

Fields

§name: String
§min: usize
§got: usize
§

VarArgTooMany

Fields

§name: String
§max: usize
§got: usize
§

VarFlagTooFew

Fields

§name: String
§min: usize
§got: usize
§

VarFlagTooMany

Fields

§name: String
§max: usize
§got: usize
§

InvalidPath(String)

§

InvalidView(String)

§

InvalidOutput(String)

A command’s output/select declarations do not agree with each other, or with the flags around them. Spanless like UsageErr::InvalidView, because selection is resolved once the whole document is read — a select may name a flag declared on an ancestor, so the node spans are long gone by the time it can be checked.

§

InvalidValue

Fields

§name: String
§value: String
§reason: String
§

UnsupportedShell(String)

§

MissingMountOutput(String)

Trait Implementations§

Source§

impl Debug for UsageErr

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for UsageErr

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Error for UsageErr

Source§

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

Returns 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
Source§

impl From<Error> for UsageErr

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for UsageErr

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<FromUtf8Error> for UsageErr

Source§

fn from(source: FromUtf8Error) -> Self

Converts to this type from the input type.
Source§

impl From<MietteError> for UsageErr

Source§

fn from(source: MietteError) -> Self

Converts to this type from the input type.
Source§

impl From<ParseError> for UsageErr

Source§

fn from(source: ParseError) -> Self

Converts to this type from the input type.
Source§

impl From<UsageErr> for Error

Source§

fn from(value: UsageErr) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.