Skip to main content

config_get/
error.rs

1use thiserror::Error;
2
3/// All errors that can occur in `config-get`.
4#[derive(Debug, Error)]
5pub enum ConfigError {
6    /// No configuration file was found in any of the searched paths.
7    #[error("no configuration file found for '{0}'")]
8    NotFound(String),
9
10    /// The file could not be read from disk.
11    #[error("I/O error reading '{path}': {source}")]
12    Io {
13        /// Path of the file that could not be read.
14        path: String,
15        /// Underlying I/O error.
16        #[source]
17        source: std::io::Error,
18    },
19
20    /// The file content could not be parsed.
21    #[error("parse error in '{path}': {message}")]
22    Parse {
23        /// Path of the file that failed to parse.
24        path: String,
25        /// Human-readable description of the parse failure.
26        message: String,
27    },
28
29    /// A required key was not found in the config.
30    #[error("key not found: '{0}'")]
31    KeyNotFound(String),
32
33    /// The requested section was not found.
34    #[error("section not found: '{0}'")]
35    SectionNotFound(String),
36
37    /// A feature required to handle this format is not enabled.
38    #[error("feature '{feature}' is not enabled; recompile with `--features {feature}`")]
39    FeatureNotEnabled {
40        /// The Cargo feature that must be enabled.
41        feature: &'static str,
42    },
43
44    /// Generic / unexpected error.
45    #[error("{0}")]
46    Other(String),
47}
48
49/// Convenience alias used throughout the crate.
50pub type Result<T, E = ConfigError> = std::result::Result<T, E>;