ddex_builder/
error.rs

1//! Error types for DDEX Builder
2
3use serde::{Deserialize, Serialize};
4use thiserror::Error;
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 that failed validation
13        field: String,
14        /// Error message describing the issue
15        message: String,
16    },
17
18    /// Missing required field
19    #[error("Missing required field: {field}")]
20    MissingRequired {
21        /// Field that failed validation
22        field: String,
23    },
24
25    /// Invalid reference
26    #[error("Invalid reference: {reference}")]
27    InvalidReference {
28        /// Reference that could not be resolved
29        reference: String,
30    },
31
32    /// Validation failed
33    #[error("Validation failed: {}", errors.join(", "))]
34    ValidationFailed {
35        /// List of validation errors
36        errors: Vec<String>,
37    },
38
39    /// IO error
40    #[error("IO error: {0}")]
41    Io(String),
42
43    /// Serialization error
44    #[error("Serialization error: {0}")]
45    Serialization(String),
46
47    /// XML generation error
48    #[error("XML generation error: {0}")]
49    XmlGeneration(String),
50
51    /// Determinism verification failed
52    #[error("Determinism verification failed: {message}")]
53    DeterminismFailed {
54        /// General error message
55        message: String,
56    },
57
58    /// Determinism guarantee violation
59    #[error("Determinism guarantee violated: {guarantee} - {details}")]
60    DeterminismGuaranteeViolated {
61        /// Guarantee that failed
62        guarantee: String,
63        /// Details about the failure
64        details: String,
65    },
66
67    /// Validation error
68    #[error("Validation error: {0}")]
69    Validation(String),
70
71    /// Parallel processing error
72    #[error("Parallel processing error: {0}")]
73    Parallel(String),
74
75    /// Security violation
76    #[error("Security violation: {0}")]
77    Security(String),
78
79    /// Input sanitization failed
80    #[error("Input sanitization failed: {0}")]
81    InputSanitization(String),
82
83    /// Other error
84    #[error("{0}")]
85    Other(String),
86}
87
88impl From<std::io::Error> for BuildError {
89    fn from(err: std::io::Error) -> Self {
90        BuildError::Io(err.to_string())
91    }
92}
93
94impl From<serde_json::Error> for BuildError {
95    fn from(err: serde_json::Error) -> Self {
96        BuildError::Serialization(err.to_string())
97    }
98}
99
100impl From<quick_xml::Error> for BuildError {
101    fn from(err: quick_xml::Error) -> Self {
102        BuildError::XmlGeneration(err.to_string())
103    }
104}
105
106/// Build warning (non-fatal)
107#[derive(Debug, Clone, Serialize, Deserialize)]
108pub struct BuildWarning {
109    /// Error code for categorization
110    pub code: String,
111    /// Human-readable error message
112    pub message: String,
113    /// Optional location information
114    pub location: Option<String>,
115}