spreadsheet_to_json/
error.rs1use std::error::Error;
2use std::fmt;
3
4
5#[derive(Debug)]
7pub struct GenericError(pub &'static str);
8
9impl fmt::Display for GenericError {
10 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11 write!(f, "{}", self.0)
12 }
13}
14
15impl Error for GenericError {}
16
17impl From<calamine::Error> for GenericError {
19 fn from(error: calamine::Error) -> Self {
20 match error {
21 calamine::Error::Io(_) => GenericError("io_error"),
22 calamine::Error::Xlsx(_) => GenericError("xlsx_error"),
23 calamine::Error::Xls(_) => GenericError("xlsx_error"),
24 calamine::Error::Ods(_) => GenericError("ods_error"),
25 _ => GenericError("unknown_calamine_error"),
27 }
28 }
29}
30
31impl From<std::io::Error> for GenericError {
33 fn from(error: std::io::Error) -> Self {
34 match error.kind() {
35 std::io::ErrorKind::NotFound => GenericError("file_not_found"),
36 std::io::ErrorKind::PermissionDenied => GenericError("permission_denied"),
37 std::io::ErrorKind::ConnectionRefused => GenericError("connection_refused"),
38 _ => GenericError("io_error"),
39 }
40 }
41}
42