1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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,
},
}