pub enum ValidationError {
FileNotFound {
path: PathBuf,
arg_name: String,
suggestion: Option<String>,
},
InvalidExtension {
arg_name: String,
path: PathBuf,
expected: Vec<String>,
},
OutOfRange {
arg_name: String,
value: f64,
min: f64,
max: f64,
suggestion: Option<String>,
},
CustomConstraint {
arg_name: String,
reason: String,
suggestion: Option<String>,
},
MissingDependency {
arg_name: String,
required_arg: String,
suggestion: Option<String>,
},
MutuallyExclusive {
arg1: String,
arg2: String,
suggestion: Option<String>,
},
}Expand description
Errors during argument validation
These errors occur after parsing, during validation of constraints defined in the configuration.
Variants§
FileNotFound
Required file doesn’t exist
§Example
use dynamic_cli::error::ValidationError;
use std::path::PathBuf;
let error = ValidationError::FileNotFound {
path: PathBuf::from("data.csv"),
arg_name: "input".to_string(),
suggestion: Some("Check that the file exists and the path is correct.".to_string()),
};
let msg = format!("{}", error);
assert!(msg.contains("data.csv"));Fields
InvalidExtension
Invalid file extension
OutOfRange
Value out of allowed range
§Example
use dynamic_cli::error::ValidationError;
let error = ValidationError::OutOfRange {
arg_name: "percentage".to_string(),
value: 150.0,
min: 0.0,
max: 100.0,
suggestion: Some("Value must be between 0 and 100.".to_string()),
};
let msg = format!("{}", error);
assert!(msg.contains("150"));Fields
CustomConstraint
Custom constraint not met
§Example
use dynamic_cli::error::ValidationError;
let error = ValidationError::CustomConstraint {
arg_name: "email".to_string(),
reason: "not a valid email address".to_string(),
suggestion: Some("Provide a valid email address (e.g. user@example.com).".to_string()),
};
let msg = format!("{}", error);
assert!(msg.contains("email"));Fields
MissingDependency
Dependency between arguments not satisfied
Some arguments require the presence of other arguments.
§Example
use dynamic_cli::error::ValidationError;
let error = ValidationError::MissingDependency {
arg_name: "output-format".to_string(),
required_arg: "output".to_string(),
suggestion: Some("Add --output to your command.".to_string()),
};
let msg = format!("{}", error);
assert!(msg.contains("output-format"));Fields
MutuallyExclusive
Mutually exclusive arguments
Some arguments cannot be used together.
§Example
use dynamic_cli::error::ValidationError;
let error = ValidationError::MutuallyExclusive {
arg1: "--verbose".to_string(),
arg2: "--quiet".to_string(),
suggestion: Some("Remove one of the two conflicting options.".to_string()),
};
let msg = format!("{}", error);
assert!(msg.contains("--verbose"));Trait Implementations§
Source§impl Debug for ValidationError
impl Debug for ValidationError
Source§impl Display for ValidationError
impl Display for ValidationError
Source§impl Error for ValidationError
impl Error for ValidationError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
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
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl From<ValidationError> for DynamicCliError
impl From<ValidationError> for DynamicCliError
Source§fn from(source: ValidationError) -> Self
fn from(source: ValidationError) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for ValidationError
impl RefUnwindSafe for ValidationError
impl Send for ValidationError
impl Sync for ValidationError
impl Unpin for ValidationError
impl UnsafeUnpin for ValidationError
impl UnwindSafe for ValidationError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more