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