Skip to main content

maec/
error.rs

1//! Error types for MAEC operations
2//!
3//! This module provides comprehensive error handling for MAEC operations
4//! including validation, serialization, and builder pattern errors.
5
6use thiserror::Error;
7
8/// Main error type for MAEC operations
9#[derive(Debug, Error)]
10pub enum MaecError {
11    /// Missing required field in builder
12    #[error("missing required field: {0}")]
13    MissingField(&'static str),
14
15    /// Invalid MAEC ID format
16    #[error("invalid MAEC ID: {0}")]
17    InvalidId(String),
18
19    /// Invalid reference to another object
20    #[error("invalid reference: {0}")]
21    InvalidReference(String),
22
23    /// JSON serialization/deserialization error
24    #[error("serialization error: {0}")]
25    SerializationError(#[from] serde_json::Error),
26
27    /// XML serialization/deserialization error
28    #[error("XML error: {0}")]
29    XmlError(String),
30
31    /// Quick-XML deserialization error
32    #[error("XML deserialization error: {0}")]
33    QuickXmlDeError(#[from] quick_xml::DeError),
34
35    /// Quick-XML serialization error
36    #[error("XML serialization error: {0}")]
37    XmlSerializationError(String),
38
39    /// Validation error
40    #[error("validation error: {0}")]
41    ValidationError(String),
42
43    /// I/O error
44    #[error("I/O error: {0}")]
45    IoError(#[from] std::io::Error),
46}
47
48/// Specialized Result type for MAEC operations
49pub type Result<T> = std::result::Result<T, MaecError>;
50
51/// Builder error type (alias for MaecError for compatibility)
52pub type BuilderError = MaecError;