Skip to main content

wolfxl_core/
error.rs

1use std::fmt;
2
3#[derive(Debug)]
4pub enum Error {
5    Io(std::io::Error),
6    Xlsx(String),
7    Format(String),
8    SheetNotFound(String),
9    InvalidRange(String),
10}
11
12impl fmt::Display for Error {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        match self {
15            Error::Io(e) => write!(f, "io error: {e}"),
16            Error::Xlsx(s) => write!(f, "xlsx error: {s}"),
17            Error::Format(s) => write!(f, "format error: {s}"),
18            Error::SheetNotFound(s) => write!(f, "sheet not found: {s:?}"),
19            Error::InvalidRange(s) => write!(f, "invalid range: {s}"),
20        }
21    }
22}
23
24impl std::error::Error for Error {
25    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
26        match self {
27            Error::Io(e) => Some(e),
28            _ => None,
29        }
30    }
31}
32
33impl From<std::io::Error> for Error {
34    fn from(e: std::io::Error) -> Self {
35        Error::Io(e)
36    }
37}
38
39pub type Result<T> = std::result::Result<T, Error>;