1use std::path::PathBuf;
8use thiserror::Error;
9
10#[derive(Error, Debug)]
13pub enum ConfigError {
14 #[error("Failed to access configuration file: {0}")]
17 IoError(#[from] std::io::Error),
18
19 #[error("Failed to parse configuration TOML: {0}")]
21 TomlError(#[from] toml::de::Error),
22
23 #[error("Failed to serialize configuration to TOML: {0}")]
25 TomlSerError(#[from] toml::ser::Error),
26
27 #[error("Configuration file not found at: {0}")]
29 FileNotFound(PathBuf),
30
31 #[error("Invalid configuration value: {0}")]
33 ValidationError(String),
34
35 #[error(
37 "Unsupported configuration version {found} (supported: {supported})"
38 )]
39 VersionError { found: String, supported: String },
40
41 #[error("Failed to access configuration directory: {0}")]
43 DirectoryError(PathBuf),
44
45 #[error("Invalid color value: {0}")]
47 ColorError(String),
48
49 #[error("Invalid input configuration: {0}")]
51 InputError(String),
52
53 #[error("Parse error: {0}")]
54 ParseError(String),
55
56 #[error("Environment configuration error: {0}")]
57 EnvError(String),
58
59 #[error("Invalid configuration path: {0}")]
60 InvalidPath(String),
61}
62
63pub type Result<T> = std::result::Result<T, ConfigError>;
65
66#[cfg(test)]
68mod tests {
69 use super::*;
70
71 #[test]
72 fn test_error_display() {
73 let err = ConfigError::ValidationError(
75 "Zoom level must be positive".to_string(),
76 );
77 assert_eq!(
78 err.to_string(),
79 "Invalid configuration value: Zoom level must be positive"
80 );
81
82 let err = ConfigError::VersionError {
83 found: "0.2".to_string(),
84 supported: "0.1".to_string(),
85 };
86 assert_eq!(
87 err.to_string(),
88 "Unsupported configuration version 0.2 (supported: 0.1)"
89 );
90 }
91}