1use thiserror::Error;
3#[derive(Debug, Error)]
6pub enum XfaError {
7 #[error("failed to load PDF: {0}")]
10 LoadFailed(String),
11 #[error("XFA packet not found: {0}")]
13 PacketNotFound(String),
14 #[error("encrypted PDF: {0}")]
16 Encrypted(String),
17 #[error("XML parse error: {0}")]
19 XmlParse(String),
20 #[error("font error: {0}")]
22 FontError(String),
23 #[error("layout error: {0}")]
25 LayoutError(String),
26 #[error("layout failed: {0}")]
28 LayoutFailed(String),
29 #[error("XML parse failed: {0}")]
31 ParseFailed(String),
32 #[error("FormCalc error: {0}")]
34 FormCalcError(String),
35 #[error("IO error: {0}")]
37 Io(#[from] std::io::Error),
38
39 #[error("XFA extraction failed: {0}")]
42 ExtractionFailed(String),
43
44 #[error("Template parse error: {0}")]
46 TemplateParse(String),
47
48 #[error("Data binding failed: {0}")]
50 BindingFailed(String),
51 #[error("Layout failed at {stage}: {reason}")]
60 LayoutFailedAt {
61 stage: String,
63 reason: String,
65 },
66
67 #[error("Render failed: {0}")]
69 RenderFailed(String),
70
71 #[error("Flatten failed: {0}")]
73 FlattenFailed(String),
74
75 #[error("unsupported feature: {0}")]
77 UnsupportedFeature(String),
78}
79pub type Result<T> = std::result::Result<T, XfaError>;
81
82#[cfg(test)]
83mod tests {
84 use super::*;
85
86 #[test]
87 fn error_message_extraction_failed() {
88 let e = XfaError::ExtractionFailed("no /AcroForm key".to_string());
89 assert_eq!(format!("{e}"), "XFA extraction failed: no /AcroForm key");
90 }
91
92 #[test]
93 fn error_message_layout_failed_at() {
94 let e = XfaError::LayoutFailedAt {
95 stage: "paginate".to_string(),
96 reason: "zero-height page area".to_string(),
97 };
98 assert_eq!(
99 format!("{e}"),
100 "Layout failed at paginate: zero-height page area"
101 );
102 }
103}