icon_loader/theme_name_provider/
error.rs

1use std::error::Error as StdError;
2use std::fmt;
3
4/// Type alias for `std::result::Result<T, Error>`
5pub type Result<T> = std::result::Result<T, Error>;
6
7/// Error type returned by [`ThemeNameProvider`](crate::ThemeNameProvider).
8#[derive(Debug)]
9pub enum Error {
10    /// Config file could not be found.
11    ConfigNotFound,
12
13    /// Error loading config file.
14    LoadConfig {
15        /// The source for the error.
16        source: ini::Error,
17    },
18
19    /// Config does not contain valid theme name.
20    ConfigMissingThemeName,
21
22    /// Wrapper for errors returned by custom [`ThemeNameProvider`](crate::ThemeNameProvider).
23    Custom {
24        /// The source for the error.
25        source: Box<dyn StdError + Send + Sync>,
26    },
27}
28
29impl StdError for Error {
30    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
31        match self {
32            Error::LoadConfig { source } => Some(source),
33            Error::Custom { source } => Some(source.as_ref()),
34            _ => None,
35        }
36    }
37}
38
39impl fmt::Display for Error {
40    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41        match self {
42            Error::ConfigNotFound => write!(f, "Config file could not be found."),
43            Error::LoadConfig { source } => write!(f, "Error loading config file: {}", source),
44            Error::ConfigMissingThemeName => {
45                write!(f, "Config file is missing a valid theme name.")
46            }
47            Error::Custom { source } => {
48                write!(f, "Error in custom theme name provider: {}", source)
49            }
50        }
51    }
52}
53
54impl From<ini::Error> for Error {
55    fn from(source: ini::Error) -> Self {
56        Error::LoadConfig { source }
57    }
58}