Skip to main content

product_os_configuration/
error.rs

1//! Configuration error types
2
3use alloc::string::String;
4use alloc::vec::Vec;
5use core::fmt;
6
7/// Error type for configuration operations
8#[derive(Debug, Clone)]
9pub enum ConfigError {
10    /// Error reading a configuration file
11    FileReadError(String),
12    /// Error parsing configuration data
13    ParseError(String),
14    /// A required configuration section is missing
15    MissingSectionError(String),
16    /// Configuration validation failed
17    ValidationError(Vec<String>),
18}
19
20impl fmt::Display for ConfigError {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        match self {
23            Self::FileReadError(msg) => write!(f, "Config file read error: {msg}"),
24            Self::ParseError(msg) => write!(f, "Config parse error: {msg}"),
25            Self::MissingSectionError(key) => write!(f, "Missing config section: {key}"),
26            Self::ValidationError(errors) => {
27                write!(f, "Config validation errors: ")?;
28                for (i, err) in errors.iter().enumerate() {
29                    if i > 0 {
30                        write!(f, "; ")?;
31                    }
32                    write!(f, "{err}")?;
33                }
34                Ok(())
35            }
36        }
37    }
38}
39
40#[cfg(feature = "std")]
41extern crate std;
42
43#[cfg(feature = "std")]
44impl std::error::Error for ConfigError {}