ddex_builder/
error.rs

1//! Error types for DDEX Builder
2
3use thiserror::Error;
4use serde::{Serialize, Deserialize};
5
6/// Build error types
7#[derive(Error, Debug, Clone, Serialize, Deserialize)]
8pub enum BuildError {
9    /// Invalid format
10    #[error("Invalid format in {field}: {message}")]
11    InvalidFormat {
12        field: String,
13        message: String,
14    },
15    
16    /// Missing required field
17    #[error("Missing required field: {field}")]
18    MissingRequired {
19        field: String,
20    },
21    
22    /// Invalid reference
23    #[error("Invalid reference: {reference}")]
24    InvalidReference {
25        reference: String,
26    },
27    
28    /// Validation failed
29    #[error("Validation failed: {}", errors.join(", "))]
30    ValidationFailed {
31        errors: Vec<String>,
32    },
33    
34    /// IO error
35    #[error("IO error: {0}")]
36    Io(String),
37    
38    /// Serialization error
39    #[error("Serialization error: {0}")]
40    Serialization(String),
41    
42    /// XML generation error
43    #[error("XML generation error: {0}")]
44    XmlGeneration(String),
45    
46    /// Determinism verification failed
47    #[error("Determinism verification failed: {message}")]
48    DeterminismFailed {
49        message: String,
50    },
51    
52    /// Determinism guarantee violation
53    #[error("Determinism guarantee violated: {guarantee} - {details}")]
54    DeterminismGuaranteeViolated {
55        guarantee: String,
56        details: String,
57    },
58    
59    /// Validation error
60    #[error("Validation error: {0}")]
61    Validation(String),
62    
63    /// Parallel processing error
64    #[error("Parallel processing error: {0}")]
65    Parallel(String),
66    
67    /// Security violation
68    #[error("Security violation: {0}")]
69    Security(String),
70    
71    /// Input sanitization failed
72    #[error("Input sanitization failed: {0}")]
73    InputSanitization(String),
74    
75    /// Other error
76    #[error("{0}")]
77    Other(String),
78}
79
80impl From<std::io::Error> for BuildError {
81    fn from(err: std::io::Error) -> Self {
82        BuildError::Io(err.to_string())
83    }
84}
85
86impl From<serde_json::Error> for BuildError {
87    fn from(err: serde_json::Error) -> Self {
88        BuildError::Serialization(err.to_string())
89    }
90}
91
92impl From<quick_xml::Error> for BuildError {
93    fn from(err: quick_xml::Error) -> Self {
94        BuildError::XmlGeneration(err.to_string())
95    }
96}
97
98/// Build warning (non-fatal)
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct BuildWarning {
101    pub code: String,
102    pub message: String,
103    pub location: Option<String>,
104}