Skip to main content

oxigdal_metadata/
error.rs

1//! Error types for metadata operations.
2
3use thiserror::Error;
4
5/// Result type for metadata operations.
6pub type Result<T> = core::result::Result<T, MetadataError>;
7
8/// Errors that can occur during metadata operations.
9#[derive(Debug, Error)]
10pub enum MetadataError {
11    /// Invalid metadata format
12    #[error("Invalid metadata format: {0}")]
13    InvalidFormat(String),
14
15    /// Missing required field
16    #[error("Missing required field: {0}")]
17    MissingField(String),
18
19    /// Invalid field value
20    #[error("Invalid field value for {field}: {reason}")]
21    InvalidValue {
22        /// Field name
23        field: String,
24        /// Reason for invalidity
25        reason: String,
26    },
27
28    /// Validation error
29    #[error("Validation failed: {0}")]
30    ValidationError(String),
31
32    /// XML parsing error
33    #[cfg(feature = "xml")]
34    #[error("XML error: {0}")]
35    XmlError(String),
36
37    /// JSON parsing error
38    #[error("JSON error: {0}")]
39    JsonError(String),
40
41    /// Transformation error
42    #[error("Transformation error: {0}")]
43    TransformError(String),
44
45    /// Extraction error
46    #[error("Extraction error: {0}")]
47    ExtractionError(String),
48
49    /// Unsupported operation
50    #[error("Unsupported operation: {0}")]
51    Unsupported(String),
52
53    /// I/O error
54    #[cfg(feature = "std")]
55    #[error("I/O error: {0}")]
56    Io(#[from] std::io::Error),
57
58    /// URL parse error
59    #[error("URL parse error: {0}")]
60    UrlError(#[from] url::ParseError),
61
62    /// Date/time parse error
63    #[error("DateTime parse error: {0}")]
64    DateTimeError(String),
65
66    /// Vocabulary error
67    #[error("Invalid vocabulary term: {0}")]
68    VocabularyError(String),
69
70    /// Internal error
71    #[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}