1use arrow::error::ArrowError;
5use parquet::errors::ParquetError;
6use std::fmt::{Debug, Display, Formatter};
7
8pub type Result<T> = std::result::Result<T, Error>;
9
10#[derive(Debug)]
11pub enum Error {
12 Arrow(ArrowError),
13 Parquet(ParquetError),
14 CityJSON(cityjson::error::Error),
15 Json(serde_json::Error),
16 Conversion(String),
17 Unsupported(String),
18 SchemaMismatch { expected: String, found: String },
19 MissingField(String),
20 Io(std::io::Error),
21}
22
23impl Display for Error {
24 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
25 match self {
26 Error::Arrow(e) => write!(f, "Arrow error: {e}"),
27 Error::Parquet(e) => write!(f, "Parquet error: {e}"),
28 Error::CityJSON(e) => write!(f, "CityJSON error: {e}"),
29 Error::Json(e) => write!(f, "JSON error: {e}"),
30 Error::Conversion(s) => write!(f, "could not convert due to {s}"),
31 Error::Unsupported(s) => write!(f, "feature {s} is not supported"),
32 Error::SchemaMismatch { expected, found } => {
33 write!(f, "expected schema: {expected}, found schema: {found}")
34 }
35 Error::MissingField(s) => write!(f, "field {s} should be present in the Arrow data"),
36 Error::Io(e) => write!(f, "IO error: {e}"),
37 }
38 }
39}
40
41impl From<ArrowError> for Error {
42 fn from(value: ArrowError) -> Self {
43 Self::Arrow(value)
44 }
45}
46
47impl From<ParquetError> for Error {
48 fn from(value: ParquetError) -> Self {
49 Self::Parquet(value)
50 }
51}
52
53impl From<cityjson::error::Error> for Error {
54 fn from(value: cityjson::error::Error) -> Self {
55 Self::CityJSON(value)
56 }
57}
58
59impl From<serde_json::Error> for Error {
60 fn from(value: serde_json::Error) -> Self {
61 Self::Json(value)
62 }
63}
64
65impl From<std::io::Error> for Error {
66 fn from(value: std::io::Error) -> Self {
67 Self::Io(value)
68 }
69}
70
71impl std::error::Error for Error {}