use std::fmt;
#[derive(Debug)]
pub enum ConfigError {
Io(std::io::Error),
Parse(serde_yaml_ng::Error),
Validation(String),
PathTraversal(String),
}
impl fmt::Display for ConfigError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ConfigError::Io(e) => write!(f, "I/O error reading config: {e}"),
ConfigError::Parse(e) => write!(f, "YAML parse error in config: {e}"),
ConfigError::Validation(msg) => write!(f, "Config validation error: {msg}"),
ConfigError::PathTraversal(msg) => write!(f, "Path traversal detected: {msg}"),
}
}
}
impl std::error::Error for ConfigError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
ConfigError::Io(e) => Some(e),
ConfigError::Parse(e) => Some(e),
ConfigError::Validation(_) | ConfigError::PathTraversal(_) => None,
}
}
}
impl From<std::io::Error> for ConfigError {
fn from(e: std::io::Error) -> Self {
ConfigError::Io(e)
}
}
impl From<serde_yaml_ng::Error> for ConfigError {
fn from(e: serde_yaml_ng::Error) -> Self {
ConfigError::Parse(e)
}
}