Skip to main content

ParseError

Enum ParseError 

Source
#[non_exhaustive]
pub enum ParseError { UnknownCommand { command: String, suggestions: Vec<String>, }, MissingArgument { argument: String, command: String, suggestion: Option<String>, }, MissingOption { option: String, command: String, suggestion: Option<String>, }, TooManyArguments { command: String, expected: usize, got: usize, suggestion: Option<String>, }, UnknownOption { flag: String, command: String, suggestions: Vec<String>, }, TypeParseError { arg_name: String, expected_type: String, value: String, details: Option<String>, }, InvalidChoice { arg_name: String, value: String, choices: Vec<String>, }, InvalidSyntax { details: String, hint: Option<String>, }, UnknownOptionParameter { option: String, discriminant: String, key: String, valid_keys: Vec<String>, suggestion: Option<String>, }, MissingRequiredOptionParameter { option: String, discriminant: String, key: String, suggestion: Option<String>, }, UnknownDiscriminant { option: String, value: String, valid_choices: Vec<String>, suggestion: Option<String>, }, DuplicateOptionOccurrence { option: String, discriminant: String, params: Vec<(String, String)>, suggestion: Option<String>, }, }
Expand description

Errors when parsing user commands

These errors occur when analyzing arguments provided by the user in CLI or REPL mode.

Marked #[non_exhaustive] (DD-024, #37): repeatable-option parsing added four variants in one release, and more argument-shape features are expected before v1.0.0. External match expressions must include a wildcard arm.

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.
§

UnknownCommand

Unknown command

The user typed a command that doesn’t exist. Includes suggestions based on Levenshtein distance.

Fields

§command: String
§suggestions: Vec<String>

Similar command suggestions (from Levenshtein distance)

§

MissingArgument

Missing required positional argument

§Example

use dynamic_cli::error::ParseError;

let error = ParseError::MissingArgument {
    argument: "filename".to_string(),
    command: "process".to_string(),
    suggestion: Some("Run --help process to see required arguments.".to_string()),
};
let msg = format!("{}", error);
assert!(msg.contains("filename"));

Fields

§argument: String
§command: String
§suggestion: Option<String>

Actionable hint surfaced to the user (not part of the Display string)

§

MissingOption

Missing required option

§Example

use dynamic_cli::error::ParseError;

let error = ParseError::MissingOption {
    option: "output".to_string(),
    command: "export".to_string(),
    suggestion: Some("Run --help export to see required options.".to_string()),
};
let msg = format!("{}", error);
assert!(msg.contains("output"));

Fields

§option: String
§command: String
§suggestion: Option<String>

Actionable hint surfaced to the user (not part of the Display string)

§

TooManyArguments

Too many positional arguments

§Example

use dynamic_cli::error::ParseError;

let error = ParseError::TooManyArguments {
    command: "run".to_string(),
    expected: 1,
    got: 3,
    suggestion: Some("Run --help run for the expected usage.".to_string()),
};
let msg = format!("{}", error);
assert!(msg.contains("run"));

Fields

§command: String
§expected: usize
§got: usize
§suggestion: Option<String>

Actionable hint surfaced to the user (not part of the Display string)

§

UnknownOption

Unknown option

Includes similar option suggestions.

Fields

§flag: String
§command: String
§suggestions: Vec<String>

Similar option suggestions (from Levenshtein distance)

§

TypeParseError

Type parsing error

The user provided a value that can’t be converted to the expected type (e.g., “abc” for an integer).

Fields

§arg_name: String
§expected_type: String
§value: String
§details: Option<String>

Error details (e.g., “not a valid integer”)

§

InvalidChoice

Value not in allowed choices

Fields

§arg_name: String
§value: String
§choices: Vec<String>
§

InvalidSyntax

Invalid command syntax

Fields

§details: String
§hint: Option<String>

Example of correct syntax

§

UnknownOptionParameter

Unknown key inside a repeatable option’s occurrence

The discriminant itself was valid, but a key=value pair used a key not declared in that discriminant’s option_parameters.

§Example

use dynamic_cli::error::ParseError;

let error = ParseError::UnknownOptionParameter {
    option: "output".to_string(),
    discriminant: "csv".to_string(),
    key: "compression".to_string(),
    valid_keys: vec!["file".to_string(), "resolution".to_string()],
    suggestion: Some("Run --help export to see valid keys for --output csv.".to_string()),
};
let msg = format!("{}", error);
assert!(msg.contains("compression"));

Fields

§option: String
§discriminant: String
§valid_keys: Vec<String>
§suggestion: Option<String>

Actionable hint surfaced to the user (not part of the Display string)

§

MissingRequiredOptionParameter

Required key missing from a repeatable option’s occurrence

§Example

use dynamic_cli::error::ParseError;

let error = ParseError::MissingRequiredOptionParameter {
    option: "output".to_string(),
    discriminant: "csv".to_string(),
    key: "file".to_string(),
    suggestion: Some("Run --help export to see required keys for --output csv.".to_string()),
};
let msg = format!("{}", error);
assert!(msg.contains("file"));

Fields

§option: String
§discriminant: String
§suggestion: Option<String>

Actionable hint surfaced to the user (not part of the Display string)

§

UnknownDiscriminant

Unknown discriminant for a repeatable option

The token immediately after a repeatable option’s flag did not match any entry in that option’s choices.

§Example

use dynamic_cli::error::ParseError;

let error = ParseError::UnknownDiscriminant {
    option: "output".to_string(),
    value: "xml".to_string(),
    valid_choices: vec!["csv".to_string(), "plot".to_string()],
    suggestion: Some("Run --help export to see valid --output kinds.".to_string()),
};
let msg = format!("{}", error);
assert!(msg.contains("xml"));

Fields

§option: String
§value: String
§valid_choices: Vec<String>
§suggestion: Option<String>

Actionable hint surfaced to the user (not part of the Display string)

§

DuplicateOptionOccurrence

The same repeatable-option occurrence was supplied twice

Raised only when two occurrences share both the same discriminant and exactly the same key=value pairs — a pure equality check the framework can make without domain knowledge. Partially-overlapping occurrences (same discriminant, different values) are not rejected here; that stays the handler’s responsibility (DD-024).

§Example

use dynamic_cli::error::ParseError;

let error = ParseError::DuplicateOptionOccurrence {
    option: "output".to_string(),
    discriminant: "csv".to_string(),
    params: vec![("file".to_string(), "results.csv".to_string())],
    suggestion: Some("Remove one of the two identical --output csv occurrences.".to_string()),
};
let msg = format!("{}", error);
assert!(msg.contains("results.csv"));

Fields

§option: String
§discriminant: String
§params: Vec<(String, String)>
§suggestion: Option<String>

Actionable hint surfaced to the user (not part of the Display string)

Implementations§

Source§

impl ParseError

Source

pub fn unknown_command_with_suggestions( command: &str, available: &[String], ) -> Self

Create an unknown command error with Levenshtein suggestions

Automatically computes similar command names from the available list.

§Arguments
  • command - The command typed by the user
  • available - List of available commands
§Example
use dynamic_cli::error::ParseError;

let available = vec!["simulate".to_string(), "validate".to_string()];
let error = ParseError::unknown_command_with_suggestions("simulat", &available);
match error {
    ParseError::UnknownCommand { suggestions, .. } => {
        assert!(suggestions.contains(&"simulate".to_string()));
    }
    _ => panic!("wrong variant"),
}
Source

pub fn unknown_option_with_suggestions( flag: &str, command: &str, available: &[String], ) -> Self

Create an unknown option error with Levenshtein suggestions

§Example
use dynamic_cli::error::ParseError;

let available = vec!["--verbose".to_string(), "--output".to_string()];
let error = ParseError::unknown_option_with_suggestions("--verbos", "run", &available);
match error {
    ParseError::UnknownOption { suggestions, .. } => {
        assert!(suggestions.contains(&"--verbose".to_string()));
    }
    _ => panic!("wrong variant"),
}
Source

pub fn missing_argument(argument: &str, command: &str) -> Self

Create a missing argument error with a help hint

The suggestion automatically refers the user to --help <command>.

§Example
use dynamic_cli::error::ParseError;

let error = ParseError::missing_argument("filename", "process");
match error {
    ParseError::MissingArgument { suggestion, .. } => {
        assert!(suggestion.is_some());
    }
    _ => panic!("wrong variant"),
}
Source

pub fn missing_option(option: &str, command: &str) -> Self

Create a missing option error with a help hint

The suggestion automatically refers the user to --help <command>.

§Example
use dynamic_cli::error::ParseError;

let error = ParseError::missing_option("output", "export");
match error {
    ParseError::MissingOption { suggestion, .. } => {
        assert!(suggestion.is_some());
    }
    _ => panic!("wrong variant"),
}
Source

pub fn too_many_arguments(command: &str, expected: usize, got: usize) -> Self

Create a too-many-arguments error with a help hint

§Example
use dynamic_cli::error::ParseError;

let error = ParseError::too_many_arguments("run", 1, 3);
match error {
    ParseError::TooManyArguments { suggestion, .. } => {
        assert!(suggestion.is_some());
    }
    _ => panic!("wrong variant"),
}

Trait Implementations§

Source§

impl Debug for ParseError

Source§

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

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

impl Display for ParseError

Source§

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

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

impl Error for ParseError

1.30.0 · 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<ParseError> for DynamicCliError

Source§

fn from(source: ParseError) -> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.