Skip to main content

apimock_config/
error.rs

1//! Errors surfaced by the config crate.
2//!
3//! See `apimock_routing::error` for the rationale on per-crate error
4//! types. `ConfigError` wraps `RoutingError` via `#[from]` so rule-set
5//! load failures flow through without the caller pattern-matching on
6//! origin.
7
8use std::{io, path::PathBuf};
9
10pub type ConfigResult<T> = Result<T, ConfigError>;
11
12#[derive(Debug, thiserror::Error)]
13pub enum ConfigError {
14    /// The config TOML file could not be read from disk.
15    #[error("failed to read config file `{path}`: {source}")]
16    ConfigRead {
17        path: PathBuf,
18        #[source]
19        source: io::Error,
20    },
21
22    /// The config TOML file was read, but could not be parsed.
23    #[error("invalid TOML in `{path}`{canonical_display}: {source}", canonical_display = match canonical {
24        Some(p) => format!(" ({})", p.display()),
25        None => String::new(),
26    })]
27    ConfigParse {
28        path: PathBuf,
29        canonical: Option<PathBuf>,
30        #[source]
31        source: toml::de::Error,
32    },
33
34    /// A path on disk could not be resolved.
35    #[error("failed to resolve path `{path}`: {source}")]
36    PathResolve {
37        path: PathBuf,
38        #[source]
39        source: io::Error,
40    },
41
42    /// Startup-time validation failed — each individual failure is
43    /// already logged at its call site.
44    #[error("configuration validation failed")]
45    Validation,
46
47    /// A rule-set file failed to load or parse. Wraps the routing
48    /// crate's error type.
49    #[error(transparent)]
50    RuleSet(#[from] apimock_routing::RoutingError),
51}