pub enum RegistryError {
DuplicateRegistration {
name: String,
suggestion: Option<String>,
},
DuplicateAlias {
alias: String,
existing_command: String,
suggestion: Option<String>,
},
MissingHandler {
command: String,
suggestion: Option<String>,
},
}Expand description
Errors related to the command registry
These errors occur when registering commands and handlers in the registry.
Variants§
DuplicateRegistration
Attempt to register an already existing command
§Example
use dynamic_cli::error::RegistryError;
let error = RegistryError::DuplicateRegistration {
name: "run".to_string(),
suggestion: Some("Command names must be unique across the registry.".to_string()),
};
let msg = format!("{}", error);
assert!(msg.contains("run"));Fields
DuplicateAlias
Alias already used by another command
§Example
use dynamic_cli::error::RegistryError;
let error = RegistryError::DuplicateAlias {
alias: "r".to_string(),
existing_command: "run".to_string(),
suggestion: Some("Choose a different alias for one of the commands.".to_string()),
};
let msg = format!("{}", error);
assert!(msg.contains("run"));Fields
MissingHandler
Missing handler for a definition
A command is defined in the config but no handler has been registered for it.
§Example
use dynamic_cli::error::RegistryError;
let error = RegistryError::MissingHandler {
command: "export".to_string(),
suggestion: Some(
"Call .register_handler(\"export\", ...) before running.".to_string()
),
};
let msg = format!("{}", error);
assert!(msg.contains("export"));Implementations§
Source§impl RegistryError
impl RegistryError
Sourcepub fn missing_handler(command: &str) -> Self
pub fn missing_handler(command: &str) -> Self
Create a missing-handler error with an actionable suggestion
The suggestion interpolates the command name so the user
knows exactly which .register_handler() call is missing.
§Example
use dynamic_cli::error::RegistryError;
let error = RegistryError::missing_handler("export");
match error {
RegistryError::MissingHandler { suggestion, .. } => {
assert!(suggestion.as_deref().unwrap_or("").contains("export"));
}
_ => panic!("wrong variant"),
}Trait Implementations§
Source§impl Debug for RegistryError
impl Debug for RegistryError
Source§impl Display for RegistryError
impl Display for RegistryError
Source§impl Error for RegistryError
impl Error for RegistryError
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<RegistryError> for DynamicCliError
impl From<RegistryError> for DynamicCliError
Source§fn from(source: RegistryError) -> Self
fn from(source: RegistryError) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for RegistryError
impl RefUnwindSafe for RegistryError
impl Send for RegistryError
impl Sync for RegistryError
impl Unpin for RegistryError
impl UnsafeUnpin for RegistryError
impl UnwindSafe for RegistryError
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