1#[derive(Debug)]
5pub enum Error {
6 Io(std::io::Error),
8
9 Ods(crate::ods::OdsError),
11 Xls(crate::xls::XlsError),
13 Xlsb(crate::xlsb::XlsbError),
15 Xlsx(crate::xlsx::XlsxError),
17 Vba(crate::vba::VbaError),
19 De(crate::de::DeError),
21
22 Msg(&'static str),
24}
25
26from_err!(std::io::Error, Error, Io);
27from_err!(crate::ods::OdsError, Error, Ods);
28from_err!(crate::xls::XlsError, Error, Xls);
29from_err!(crate::xlsb::XlsbError, Error, Xlsb);
30from_err!(crate::xlsx::XlsxError, Error, Xlsx);
31from_err!(crate::vba::VbaError, Error, Vba);
32from_err!(crate::de::DeError, Error, De);
33from_err!(&'static str, Error, Msg);
34
35impl std::fmt::Display for Error {
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 match self {
38 Error::Io(e) => write!(f, "I/O error: {}", e),
39 Error::Ods(e) => write!(f, "Ods error: {}", e),
40 Error::Xls(e) => write!(f, "Xls error: {}", e),
41 Error::Xlsx(e) => write!(f, "Xlsx error: {}", e),
42 Error::Xlsb(e) => write!(f, "Xlsb error: {}", e),
43 Error::Vba(e) => write!(f, "Vba error: {}", e),
44 Error::De(e) => write!(f, "Deserializer error: {}", e),
45 Error::Msg(msg) => write!(f, "{}", msg),
46 }
47 }
48}
49
50impl std::error::Error for Error {
51 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
52 match self {
53 Error::Io(e) => Some(e),
54 Error::Ods(e) => Some(e),
55 Error::Xls(e) => Some(e),
56 Error::Xlsb(e) => Some(e),
57 Error::Xlsx(e) => Some(e),
58 Error::Vba(e) => Some(e),
59 Error::De(e) => Some(e),
60 Error::Msg(_) => None,
61 }
62 }
63}