use thiserror::Error;
pub type Result<T> = core::result::Result<T, MetadataError>;
#[derive(Debug, Error)]
pub enum MetadataError {
#[error("Invalid metadata format: {0}")]
InvalidFormat(String),
#[error("Missing required field: {0}")]
MissingField(String),
#[error("Invalid field value for {field}: {reason}")]
InvalidValue {
field: String,
reason: String,
},
#[error("Validation failed: {0}")]
ValidationError(String),
#[cfg(feature = "xml")]
#[error("XML error: {0}")]
XmlError(String),
#[error("JSON error: {0}")]
JsonError(String),
#[error("Transformation error: {0}")]
TransformError(String),
#[error("Extraction error: {0}")]
ExtractionError(String),
#[error("Unsupported operation: {0}")]
Unsupported(String),
#[cfg(feature = "std")]
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("URL parse error: {0}")]
UrlError(#[from] url::ParseError),
#[error("DateTime parse error: {0}")]
DateTimeError(String),
#[error("Invalid vocabulary term: {0}")]
VocabularyError(String),
#[error("Internal error: {0}")]
Internal(String),
}
#[cfg(feature = "xml")]
impl From<quick_xml::Error> for MetadataError {
fn from(err: quick_xml::Error) -> Self {
MetadataError::XmlError(err.to_string())
}
}
#[cfg(feature = "xml")]
impl From<quick_xml::DeError> for MetadataError {
fn from(err: quick_xml::DeError) -> Self {
MetadataError::XmlError(err.to_string())
}
}
impl From<serde_json::Error> for MetadataError {
fn from(err: serde_json::Error) -> Self {
MetadataError::JsonError(err.to_string())
}
}
impl From<chrono::ParseError> for MetadataError {
fn from(err: chrono::ParseError) -> Self {
MetadataError::DateTimeError(err.to_string())
}
}