Skip to main content

sword_core/config/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum ConfigError {
5    #[error("Configuration file not found at config/config.toml")]
6    FileNotFound,
7
8    #[error("Failed to read configuration file: {source}")]
9    ReadError {
10        #[from]
11        source: std::io::Error,
12    },
13
14    #[error("Environment variable interpolation error: {message}")]
15    InterpolationError { message: String },
16
17    #[error("Configuration key '{key}' not found")]
18    KeyNotFound { key: String },
19
20    #[error("Deserialization error: {source}")]
21    DeserializeError {
22        #[from]
23        source: toml::de::Error,
24    },
25}
26
27impl ConfigError {
28    pub fn interpolation_error(message: String) -> Self {
29        ConfigError::InterpolationError { message }
30    }
31
32    pub fn key_not_found(key: impl Into<String>) -> Self {
33        ConfigError::KeyNotFound { key: key.into() }
34    }
35}