#[non_exhaustive]pub enum ClickError {
UsageError {
message: String,
ctx: Option<Box<ErrorContext>>,
},
BadParameter {
message: String,
param_name: Option<String>,
param_hint: Option<Vec<String>>,
ctx: Option<Box<ErrorContext>>,
},
MissingParameter {
message: Option<String>,
param_name: Option<String>,
param_hint: Option<Vec<String>>,
param_type: ParamType,
ctx: Option<Box<ErrorContext>>,
},
NoSuchOption {
option_name: String,
possibilities: Option<Vec<String>>,
ctx: Option<Box<ErrorContext>>,
},
BadOptionUsage {
option_name: String,
message: String,
ctx: Option<Box<ErrorContext>>,
},
BadArgumentUsage {
message: String,
ctx: Option<Box<ErrorContext>>,
},
FileError {
filename: PathBuf,
hint: String,
},
Abort,
Exit {
code: i32,
},
}Expand description
The main error type for click-rs.
This enum represents all possible errors that can occur during CLI parsing
and execution. It is marked #[non_exhaustive] to allow adding new variants
in future versions without breaking compatibility.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
UsageError
A general usage error with the command.
This is the base error type for command usage problems. Exit code: 2
Fields
ctx: Option<Box<ErrorContext>>Optional context for formatting
BadParameter
A parameter received an invalid value.
This error is raised when a callback or type conversion fails. Exit code: 2
Fields
ctx: Option<Box<ErrorContext>>Optional context for formatting
MissingParameter
A required parameter was not provided.
This error is raised when a required option or argument is missing. Exit code: 2
Fields
ctx: Option<Box<ErrorContext>>Optional context for formatting
NoSuchOption
An unknown option was provided.
This error includes possible corrections if similar options exist. Exit code: 2
Fields
ctx: Option<Box<ErrorContext>>Optional context for formatting
BadOptionUsage
An option was used incorrectly.
For example, wrong number of arguments for an option. Exit code: 2
Fields
ctx: Option<Box<ErrorContext>>Optional context for formatting
BadArgumentUsage
An argument was used incorrectly.
For example, wrong number of values for an argument. Exit code: 2
Fields
ctx: Option<Box<ErrorContext>>Optional context for formatting
FileError
A file operation failed.
Exit code: 1
Fields
Abort
The user aborted the operation.
This is typically raised when the user presses Ctrl+C or answers “no” to a confirmation prompt. Exit code: 1
Exit
Exit with a specific code.
This is used to signal that the application should exit with the given status code. A code of 0 indicates success.
Implementations§
Source§impl ClickError
impl ClickError
Sourcepub fn exit_code(&self) -> i32
pub fn exit_code(&self) -> i32
Get the exit code for this error.
Returns the appropriate exit code based on the error type:
Exit: returns the specified codeUsageErrorvariants: returns 2- Other errors: returns 1
Sourcepub fn format_message(&self) -> String
pub fn format_message(&self) -> String
Format the error message for display to the user.
This method returns a user-friendly error message, potentially including usage information and help hints based on the error context.
Sourcepub fn format_full(&self) -> String
pub fn format_full(&self) -> String
Format the complete error output including usage and help hints.
This method returns the full error output that should be shown to the user, including any usage information and “Try –help” hints.
Sourcepub fn is_usage_error(&self) -> bool
pub fn is_usage_error(&self) -> bool
Check if this is a usage error (exit code 2).
Sourcepub fn context(&self) -> Option<&ErrorContext>
pub fn context(&self) -> Option<&ErrorContext>
Get the error context, if any.
Sourcepub fn with_context(self, ctx: ErrorContext) -> Self
pub fn with_context(self, ctx: ErrorContext) -> Self
Attach context to this error.
This method consumes the error and returns a new error with the given context.
Source§impl ClickError
impl ClickError
Sourcepub fn bad_parameter(message: impl Into<String>) -> Self
pub fn bad_parameter(message: impl Into<String>) -> Self
Create a new bad parameter error.
Sourcepub fn bad_parameter_named(
message: impl Into<String>,
param_name: impl Into<String>,
) -> Self
pub fn bad_parameter_named( message: impl Into<String>, param_name: impl Into<String>, ) -> Self
Create a new bad parameter error with a parameter name.
Sourcepub fn missing_option(name: impl Into<String>) -> Self
pub fn missing_option(name: impl Into<String>) -> Self
Create a new missing parameter error.
Sourcepub fn missing_argument(name: impl Into<String>) -> Self
pub fn missing_argument(name: impl Into<String>) -> Self
Create a new missing argument error.
Sourcepub fn no_such_option(option_name: impl Into<String>) -> Self
pub fn no_such_option(option_name: impl Into<String>) -> Self
Create a new “no such option” error.
Sourcepub fn no_such_option_with_suggestions(
option_name: impl Into<String>,
possibilities: Vec<String>,
) -> Self
pub fn no_such_option_with_suggestions( option_name: impl Into<String>, possibilities: Vec<String>, ) -> Self
Create a new “no such option” error with suggestions.
Sourcepub fn bad_option_usage(
option_name: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn bad_option_usage( option_name: impl Into<String>, message: impl Into<String>, ) -> Self
Create a new bad option usage error.
Sourcepub fn bad_argument_usage(message: impl Into<String>) -> Self
pub fn bad_argument_usage(message: impl Into<String>) -> Self
Create a new bad argument usage error.
Trait Implementations§
Source§impl Debug for ClickError
impl Debug for ClickError
Source§impl Display for ClickError
impl Display for ClickError
Source§impl Error for ClickError
impl Error for ClickError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()