dark_light/
error.rs

1use std::fmt::Display;
2
3/// An error that can occur when detecting the system theme mode.
4#[derive(Debug)]
5pub enum Error {
6    /// If an I/O error occurs.
7    Io(std::io::Error),
8    /// If the XDG Desktop Portal could not be communicated with.
9    XdgDesktopPortal(String),
10    /// If the timeout is reached.
11    Timeout,
12    /// Failed to get persistent domain for Apple Global Domain.
13    PersistentDomainFailed,
14    /// If the window could not be found.
15    WindowNotFound,
16    /// If the media query could not be executed.
17    MediaQueryFailed,
18    /// If the media query is not supported.
19    MediaQueryNotSupported,
20}
21
22impl Display for Error {
23    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24        match self {
25            Error::Io(error) => write!(f, "I/O error: {}", error),
26            Error::XdgDesktopPortal(err) => write!(f, "XDG Desktop Portal error: {}", err),
27            Error::Timeout => write!(f, "Timeout reached"),
28            Error::PersistentDomainFailed => {
29                write!(f, "Failed to get persistent domain for Apple Global Domain")
30            }
31            Error::WindowNotFound => write!(f, "Window not found"),
32            Error::MediaQueryFailed => write!(f, "Media query failed"),
33            Error::MediaQueryNotSupported => write!(f, "Media query not supported"),
34        }
35    }
36}
37
38impl std::error::Error for Error {}
39
40impl From<std::io::Error> for Error {
41    fn from(error: std::io::Error) -> Self {
42        Error::Io(error)
43    }
44}