use std::path::PathBuf;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum ConfigError {
#[error("Failed to access configuration file: {0}")]
IoError(#[from] std::io::Error),
#[error("Failed to parse configuration TOML: {0}")]
TomlError(#[from] toml::de::Error),
#[error("Failed to serialize configuration to TOML: {0}")]
TomlSerError(#[from] toml::ser::Error),
#[error("Configuration file not found at: {0}")]
FileNotFound(PathBuf),
#[error("Invalid configuration value: {0}")]
ValidationError(String),
#[error(
"Unsupported configuration version {found} (supported: {supported})"
)]
VersionError { found: String, supported: String },
#[error("Failed to access configuration directory: {0}")]
DirectoryError(PathBuf),
#[error("Invalid color value: {0}")]
ColorError(String),
#[error("Invalid input configuration: {0}")]
InputError(String),
#[error("Parse error: {0}")]
ParseError(String),
#[error("Environment configuration error: {0}")]
EnvError(String),
#[error("Invalid configuration path: {0}")]
InvalidPath(String),
}
pub type Result<T> = std::result::Result<T, ConfigError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_display() {
let err = ConfigError::ValidationError(
"Zoom level must be positive".to_string(),
);
assert_eq!(
err.to_string(),
"Invalid configuration value: Zoom level must be positive"
);
let err = ConfigError::VersionError {
found: "0.2".to_string(),
supported: "0.1".to_string(),
};
assert_eq!(
err.to_string(),
"Unsupported configuration version 0.2 (supported: 0.1)"
);
}
}