oxigdal_metadata/
error.rs1use thiserror::Error;
4
5pub type Result<T> = core::result::Result<T, MetadataError>;
7
8#[derive(Debug, Error)]
10pub enum MetadataError {
11 #[error("Invalid metadata format: {0}")]
13 InvalidFormat(String),
14
15 #[error("Missing required field: {0}")]
17 MissingField(String),
18
19 #[error("Invalid field value for {field}: {reason}")]
21 InvalidValue {
22 field: String,
24 reason: String,
26 },
27
28 #[error("Validation failed: {0}")]
30 ValidationError(String),
31
32 #[cfg(feature = "xml")]
34 #[error("XML error: {0}")]
35 XmlError(String),
36
37 #[error("JSON error: {0}")]
39 JsonError(String),
40
41 #[error("Transformation error: {0}")]
43 TransformError(String),
44
45 #[error("Extraction error: {0}")]
47 ExtractionError(String),
48
49 #[error("Unsupported operation: {0}")]
51 Unsupported(String),
52
53 #[cfg(feature = "std")]
55 #[error("I/O error: {0}")]
56 Io(#[from] std::io::Error),
57
58 #[error("URL parse error: {0}")]
60 UrlError(#[from] url::ParseError),
61
62 #[error("DateTime parse error: {0}")]
64 DateTimeError(String),
65
66 #[error("Invalid vocabulary term: {0}")]
68 VocabularyError(String),
69
70 #[error("Internal error: {0}")]
72 Internal(String),
73}
74
75#[cfg(feature = "xml")]
76impl From<quick_xml::Error> for MetadataError {
77 fn from(err: quick_xml::Error) -> Self {
78 MetadataError::XmlError(err.to_string())
79 }
80}
81
82#[cfg(feature = "xml")]
83impl From<quick_xml::DeError> for MetadataError {
84 fn from(err: quick_xml::DeError) -> Self {
85 MetadataError::XmlError(err.to_string())
86 }
87}
88
89impl From<serde_json::Error> for MetadataError {
90 fn from(err: serde_json::Error) -> Self {
91 MetadataError::JsonError(err.to_string())
92 }
93}
94
95impl From<chrono::ParseError> for MetadataError {
96 fn from(err: chrono::ParseError) -> Self {
97 MetadataError::DateTimeError(err.to_string())
98 }
99}