use thiserror::Error;
#[derive(Error, Debug)]
pub enum ModelError {
#[error("Configuration file not found")]
FileNotFound,
#[error("IO error: {0}")]
IOError(std::io::Error),
#[error("Permission error, cannot access configuration file")]
PermissionError,
#[error("Serde parse error: {0}")]
SerdeParseError(serde_yaml::Error),
#[error("Validation Error: {item_id}.{key} = `{value}` (Rule: {rule})")]
ValidationError {
item_id: String,
key: String,
value: String,
rule: String,
},
}
impl ModelError {
pub fn validation_error(item_id: &str, key_value: (&str, &str), rule: &str) -> ModelError {
return ModelError::ValidationError {
item_id: item_id.to_string(),
key: key_value.0.to_string(),
value: key_value.1.to_string(),
rule: rule.to_string(),
};
}
}