1use std::path::PathBuf;
2
3#[derive(Debug, thiserror::Error)]
4pub enum ConfigError {
5 #[error("Configuration file not found")]
6 NotFound,
7
8 #[error("Failed to read configuration file {path}: {source}")]
9 ReadError {
10 path: PathBuf,
11 source: std::io::Error,
12 },
13
14 #[error("Failed to parse configuration: {source}")]
15 ParseError {
16 #[from]
17 source: toml::de::Error,
18 },
19
20 #[error("Validation error in {field}: {message}")]
21 ValidationError { field: String, message: String },
22
23 #[error("Missing required environment variable: {name}")]
24 MissingEnvVar { name: String },
25
26 #[error("Multiple configuration errors")]
27 MultipleErrors { errors: Vec<ConfigError> },
28}
29
30impl ConfigError {
31 pub const fn error_code(&self) -> &'static str {
32 match self {
33 Self::NotFound => "config_not_found",
34 Self::ReadError { .. } => "config_read_error",
35 Self::ParseError { .. } => "config_parse_error",
36 Self::ValidationError { .. } => "config_validation_error",
37 Self::MissingEnvVar { .. } => "config_missing_env",
38 Self::MultipleErrors { .. } => "config_multiple_errors",
39 }
40 }
41}