use thiserror::Error;
#[derive(Debug, Error)]
pub enum XmpError {
#[error("Bad parameter: {0}")]
BadParam(String),
#[error("Bad value: {0}")]
BadValue(String),
#[error("Bad schema: {0}")]
BadSchema(String),
#[error("Bad XPath: {0}")]
BadXPath(String),
#[error("Parse error: {0}")]
ParseError(String),
#[error("Serialization error: {0}")]
SerializationError(String),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("Internal error: {0}")]
InternalError(String),
#[error("Resource not found: {0}")]
NotFound(String),
#[error("Operation not supported: {0}")]
NotSupported(String),
}
pub type XmpResult<T> = Result<T, XmpError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_display() {
let err = XmpError::BadParam("test".to_string());
assert!(err.to_string().contains("Bad parameter: test"));
}
#[test]
fn test_io_error_conversion() {
let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
let xmp_err: XmpError = io_err.into();
assert!(matches!(xmp_err, XmpError::IoError(_)));
}
}