ratatui_image/
errors.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::sync::mpsc::RecvTimeoutError;

#[derive(Debug, thiserror::Error)]
pub enum Errors {
    #[error("Could not detect font size")]
    NoFontSize,
    #[error("Could not detect any graphics nor font capabilities")]
    NoCap,
    #[error("Timeout: {0}")]
    Timeout(#[from] RecvTimeoutError),
    #[error("Sixel error: {0}")]
    Sixel(String),
    #[error("Tmux error: {0}")]
    Tmux(&'static str),
    #[error("IO error: {0}")]
    IO(#[from] std::io::Error),
    #[error("Image error: {0}")]
    Image(#[from] image::error::ImageError),
}

#[cfg(not(windows))]
impl From<rustix::io::Errno> for Errors {
    fn from(errno: rustix::io::Errno) -> Self {
        Errors::IO(std::io::Error::from(errno))
    }
}

#[cfg(windows)]
impl From<windows::core::Error> for Errors {
    fn from(err: windows::core::Error) -> Self {
        Errors::IO(std::io::Error::new(
            std::io::ErrorKind::Other,
            err.to_string(),
        ))
    }
}