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 {
29 provider: String,
30 message: String,
31 },
32
33 /// A generic error.
34 #[error("{0}")]
35 Other(String),
36}
37
38impl ConfigError {
39 /// Create a new provider error.
40 pub fn provider_error<P: fmt::Display, M: fmt::Display>(provider: P, message: M) -> Self {
41 Self::ProviderError {
42 provider: provider.to_string(),
43 message: message.to_string(),
44 }
45 }
46}