foxy/config/error.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! Error types for the configuration module.
6
7use std::fmt;
8use std::io;
9use thiserror::Error;
10
11/// Errors that can occur during configuration operations.
12#[derive(Error, Debug)]
13pub enum ConfigError {
14 /// The requested configuration key was not found.
15 #[error("configuration key not found")]
16 NotFound,
17
18 /// An error occurred while parsing or deserializing a configuration value.
19 #[error("failed to parse configuration: {0}")]
20 ParseError(String),
21
22 /// An IO error occurred (e.g., while reading a configuration file).
23 #[error("IO error: {0}")]
24 IoError(#[from] io::Error),
25
26 /// An error related to a specific configuration provider.
27 #[error("provider error: {provider}: {message}")]
28 ProviderError { provider: String, message: String },
29
30 /// A generic error.
31 #[error("{0}")]
32 Other(String),
33}
34
35impl ConfigError {
36 /// Create a new provider error.
37 pub fn provider_error<P: fmt::Display, M: fmt::Display>(provider: P, message: M) -> Self {
38 Self::ProviderError {
39 provider: provider.to_string(),
40 message: message.to_string(),
41 }
42 }
43}