voxora_config/error.rs
1//! Errors returned by voxora-config.
2//!
3//! Only the optional TOML file loader can fail — every other lookup in
4//! the cascade either finds a value or falls through to the next layer,
5//! so [`ConfigError`] is exclusively about reading and parsing a file.
6
7use std::path::PathBuf;
8use thiserror::Error;
9
10/// All errors that may occur while loading a voxora configuration.
11#[derive(Debug, Error)]
12#[non_exhaustive]
13pub enum ConfigError {
14 /// The requested config file does not exist. Callers that treat a
15 /// missing file as "just use the defaults" should match on this
16 /// variant instead of ignoring every error.
17 #[error("config file not found: {}", .0.display())]
18 FileNotFound(PathBuf),
19
20 /// The config file exists but could not be read.
21 #[error("config file could not be read: {}: {message}", path.display())]
22 FileIo {
23 /// Path that failed to read.
24 path: PathBuf,
25 /// Human-readable description of the failing operation.
26 message: String,
27 /// Underlying error.
28 #[source]
29 source: std::io::Error,
30 },
31
32 /// The config file was read but is not valid TOML, or contains a
33 /// key that does not belong to the schema.
34 ///
35 /// The parser error is boxed: `toml::de::Error` alone is larger
36 /// than the whole rest of this enum, and every `Result` in the
37 /// crate would pay for it.
38 #[error("config file is not valid TOML: {}: {message}", path.display())]
39 FileParse {
40 /// Path that failed to parse (`"inline"` for string input).
41 path: PathBuf,
42 /// Human-readable description from the TOML parser.
43 message: String,
44 /// Underlying error.
45 #[source]
46 source: Box<toml::de::Error>,
47 },
48}