configbuilder-pattern-loader 0.1.0

configbuilder-pattern: loader domain, trait contract + tech-agnostic reference implementation.
Documentation
use thiserror::Error;

/// Errors returned by config loading and validation operations.
///
/// Returned by [`Loader::load_section`], [`FeatureLoader::load_feature`], and
/// every real `LoaderOps` implementor. Match on the variant to decide whether
/// to abort startup or log and continue.
///
/// [`Loader::load_section`]: crate::Loader::load_section
/// [`FeatureLoader::load_feature`]: crate::FeatureLoader::load_feature
#[derive(Debug, Error)]
pub enum ConfigError {
    /// A TOML file could not be parsed.
    #[error("config parse error: {0}")]
    Parse(String),

    /// An I/O or filesystem constraint was violated.
    #[error("config io error: {0}")]
    Io(String),

    /// No config file was found in any configured directory.
    ///
    /// Returned by [`crate::Loader::load_section`] when every candidate directory
    /// either does not exist or contains no config file. This usually indicates a
    /// misconfigured config path rather than an intentionally absent section.
    #[error("config not found: {0}")]
    NotFound(String),

    /// A cross-field or semantic constraint was violated after deserialization.
    ///
    /// Returned when a TOML section is present and parses successfully but
    /// fails the post-deserialization validation defined by
    /// [`OptionalSection::validate_enabled`].
    ///
    /// [`OptionalSection::validate_enabled`]: crate::OptionalSection::validate_enabled
    #[error("config validation error in section '{section}': {reason}")]
    Validation {
        /// The TOML section key where the violation was detected (e.g. `"message_broker"`).
        section: String,
        /// Human-readable description of the constraint that was violated.
        reason: String,
    },
}