Skip to main content

serenade_config/
error.rs

1//! Configuration load and merge errors.
2
3use std::path::PathBuf;
4
5/// Failure while loading, merging, or interpolating configuration.
6#[derive(Debug, thiserror::Error)]
7pub enum ConfigError {
8    /// Filesystem error while reading a config file or packages directory.
9    #[error("config io error at {path}: {source}")]
10    Io {
11        /// Path that failed.
12        path: PathBuf,
13        /// Underlying io error.
14        #[source]
15        source: std::io::Error,
16    },
17    /// YAML document could not be parsed.
18    #[error("invalid YAML: {0}")]
19    Yaml(#[from] serde_yaml::Error),
20    /// TOML document could not be parsed.
21    #[error("invalid TOML: {0}")]
22    Toml(#[from] toml::de::Error),
23    /// JSON conversion failed while normalizing a document.
24    #[error("invalid config document: {0}")]
25    Json(#[from] serde_json::Error),
26    /// Root value is not a mapping.
27    #[error("config root must be a mapping")]
28    InvalidRoot,
29    /// File extension is not YAML or TOML.
30    #[error("unsupported config format: {path}")]
31    UnsupportedFormat {
32        /// Path with an unknown extension.
33        path: PathBuf,
34    },
35    /// `${VAR}` placeholder is malformed.
36    #[error("invalid environment interpolation")]
37    InvalidInterpolation,
38    /// Environment variable is required and unset.
39    #[error("missing environment variable `{name}`")]
40    MissingEnvironment {
41        /// Variable name.
42        name: String,
43    },
44    /// A `.env` file could not be loaded.
45    #[error("dotenv error at {path}: {message}")]
46    Dotenv {
47        /// Path that failed.
48        path: PathBuf,
49        /// Human-readable parse or IO message.
50        message: String,
51    },
52}