use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ActionError {
Argument {
action: String,
parameter: String,
reason: String,
},
UnboundArray {
action: String,
keys: String,
parameters: String,
parameter: String,
},
Rule {
action: String,
rule: String,
},
Unknown {
name: String,
},
NotDefined {
key: String,
},
}
impl fmt::Display for ActionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Argument {
action,
parameter,
reason,
} => write!(f, "{action}::handle() argument `{parameter}` is invalid: {reason}"),
Self::UnboundArray {
action,
keys,
parameters,
parameter,
} => write!(
f,
"{action}::handle() received a single array whose keys ({keys}) match none of its parameters ({parameters}), so `{parameter}` was left empty. If the array is meant as one argument, pass it by name: run(args! {{ {parameter}: .. }})."
),
Self::Rule { action, rule } => write!(
f,
"{action} uses the validation rule `{rule}`, which Laractions does not support."
),
Self::Unknown { name } => write!(
f,
"No action is registered as `{name}`. Did you forget `#[action]` on its impl?"
),
Self::NotDefined { key } => write!(f, "Action `{key}` is not defined in the model's actions array."),
}
}
}
impl std::error::Error for ActionError {}