winbrew_database\config/
error.rs

1use thiserror::Error;
2
3/// Errors raised while validating config values.
4///
5/// `InvalidValue` in [`ConfigError`] is reserved for raw values that fail to
6/// parse or normalize, while `Validation` means the key-specific validator
7/// rejected a value that was otherwise structurally valid.
8#[derive(Debug, Error)]
9pub enum ConfigValidationError {
10    /// `core.log_level` is parsed by `tracing_subscriber::EnvFilter`, so the
11    /// original parser reason is preserved in the error.
12    #[error("invalid core.log_level '{value}': {reason}")]
13    InvalidLogLevel { value: String, reason: String },
14
15    /// `core.file_log_level` is parsed by `tracing_subscriber::EnvFilter`, so
16    /// the original parser reason is preserved in the error.
17    #[error("invalid core.file_log_level '{value}': {reason}")]
18    InvalidFileLogLevel { value: String, reason: String },
19
20    #[error("expected a boolean value (true/false, 1/0, yes/no, on/off), got '{value}'")]
21    ExpectedBoolean { value: String },
22}
23
24/// Errors raised while reading, parsing, or validating config values.
25#[derive(Debug, Error)]
26pub enum ConfigError {
27    #[error("config key cannot be empty")]
28    EmptyKey,
29
30    #[error("unknown config key: {key}")]
31    UnknownKey { key: String },
32
33    /// The raw value could not be parsed into the target config representation.
34    #[error("invalid {key} value: {value}")]
35    InvalidValue { key: String, value: String },
36
37    /// The value parsed successfully, but failed a key-specific validator.
38    #[error("invalid value for '{key}'")]
39    Validation {
40        key: String,
41        #[source]
42        source: ConfigValidationError,
43    },
44}
45
46pub type ConfigResult<T> = std::result::Result<T, ConfigError>;