Skip to main content

molten_config/
error.rs

1//! Defines the error types specific to the `molten-config` crate.
2//!
3//! This module encapsulates various errors that can occur during configuration
4//! parsing, loading, and validation, providing a centralized and
5//! `thiserror`-driven approach to error handling for configuration operations.
6use thiserror::Error;
7
8/// Represents errors that occur during configuration parsing, loading, and validation.
9#[derive(Error, Debug)]
10pub enum ConfigError {
11    /// Error originating from the `config` crate when building configuration.
12    #[error("Configuration build failed: {0}")]
13    ConfigBuildError(#[from] config::ConfigError),
14
15    /// Error indicating a failure to read a configuration file from the filesystem.
16    #[error("Failed to read file '{0}': {1}")]
17    FileReadError(String, std::io::Error),
18
19    /// Error for unsupported or unknown file extensions during configuration loading.
20    #[error("Unknown file extension '{0}'. Supported: .yaml, .yml, .json, .toml")]
21    UnknownFormat(String),
22
23    /// Error encountered during YAML deserialization.
24    #[error("YAML parsing error: {0}")]
25    YamlError(#[from] serde_yaml::Error),
26
27    /// Error encountered during JSON deserialization.
28    #[error("JSON parsing error: {0}")]
29    JsonError(#[from] serde_json::Error),
30
31    /// Error encountered during TOML deserialization.
32    #[error("TOML parsing error: {0}")]
33    TomlError(#[from] toml::de::Error),
34
35    /// Error due to validation failures of configuration entities.
36    #[error("Validation failed: {0}")]
37    ValidationErrors(#[from] validator::ValidationErrors),
38}