Skip to main content

configbuilder_pattern_loader/
error.rs

1use thiserror::Error;
2
3/// Errors returned by config loading and validation operations.
4///
5/// Returned by [`Loader::load_section`], [`FeatureLoader::load_feature`], and
6/// every real `LoaderOps` implementor. Match on the variant to decide whether
7/// to abort startup or log and continue.
8///
9/// [`Loader::load_section`]: crate::Loader::load_section
10/// [`FeatureLoader::load_feature`]: crate::FeatureLoader::load_feature
11#[derive(Debug, Error)]
12pub enum ConfigError {
13    /// A TOML file could not be parsed.
14    #[error("config parse error: {0}")]
15    Parse(String),
16
17    /// An I/O or filesystem constraint was violated.
18    #[error("config io error: {0}")]
19    Io(String),
20
21    /// No config file was found in any configured directory.
22    ///
23    /// Returned by [`crate::Loader::load_section`] when every candidate directory
24    /// either does not exist or contains no config file. This usually indicates a
25    /// misconfigured config path rather than an intentionally absent section.
26    #[error("config not found: {0}")]
27    NotFound(String),
28
29    /// A cross-field or semantic constraint was violated after deserialization.
30    ///
31    /// Returned when a TOML section is present and parses successfully but
32    /// fails the post-deserialization validation defined by
33    /// [`OptionalSection::validate_enabled`].
34    ///
35    /// [`OptionalSection::validate_enabled`]: crate::OptionalSection::validate_enabled
36    #[error("config validation error in section '{section}': {reason}")]
37    Validation {
38        /// The TOML section key where the violation was detected (e.g. `"message_broker"`).
39        section: String,
40        /// Human-readable description of the constraint that was violated.
41        reason: String,
42    },
43}