1use std::fmt;
2
3pub type Result<T> = std::result::Result<T, Error>;
5
6#[derive(Debug)]
8pub enum Error {
9 Configuration(String),
11 Xml(roxmltree::Error),
13 UnsupportedXml(&'static str),
15 Field {
17 name: String,
19 path: String,
21 message: String,
23 },
24 BatchFull,
26 Arrow(arrow_schema::ArrowError),
28}
29
30impl fmt::Display for Error {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 Self::Configuration(message) => write!(f, "invalid configuration: {message}"),
34 Self::Xml(source) => write!(f, "XML: {source}"),
35 Self::UnsupportedXml(message) => write!(f, "unsupported XML: {message}"),
36 Self::Field {
37 name,
38 path,
39 message,
40 } => write!(f, "field {name:?} at {path:?}: {message}"),
41 Self::BatchFull => f.write_str("batch is full; flush before appending"),
42 Self::Arrow(source) => write!(f, "Arrow: {source}"),
43 }
44 }
45}
46
47impl std::error::Error for Error {
48 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
49 match self {
50 Self::Xml(source) => Some(source),
51 Self::Arrow(source) => Some(source),
52 _ => None,
53 }
54 }
55}
56
57impl From<roxmltree::Error> for Error {
58 fn from(source: roxmltree::Error) -> Self {
59 Self::Xml(source)
60 }
61}
62
63impl From<arrow_schema::ArrowError> for Error {
64 fn from(source: arrow_schema::ArrowError) -> Self {
65 Self::Arrow(source)
66 }
67}