Skip to main content

cossh/config/
errors.rs

1//! Configuration-related error types.
2
3use std::{error::Error, fmt, io};
4
5/// Errors returned by configuration loading and initialization.
6#[derive(Debug)]
7pub enum ConfigError {
8    /// I/O error while reading or writing config files.
9    IoError(io::Error),
10    /// Configuration was initialized more than once in an invalid context.
11    AlreadyInitialized,
12}
13
14impl fmt::Display for ConfigError {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            ConfigError::IoError(err) => write!(f, "I/O error: {}", err),
18            ConfigError::AlreadyInitialized => write!(f, "Configuration has already been initialized"),
19        }
20    }
21}
22
23impl Error for ConfigError {}
24
25impl From<io::Error> for ConfigError {
26    fn from(err: io::Error) -> Self {
27        ConfigError::IoError(err)
28    }
29}