1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//! Error types for the XFA engine.
use thiserror::Error;
/// XfaError.
#[derive(Debug, Error)]
pub enum XfaError {
/// LoadFailed.
// ---- Existing variants (preserved for backwards compatibility) ----
#[error("failed to load PDF: {0}")]
LoadFailed(String),
/// PacketNotFound.
#[error("XFA packet not found: {0}")]
PacketNotFound(String),
/// Encrypted.
#[error("encrypted PDF: {0}")]
Encrypted(String),
/// XmlParse.
#[error("XML parse error: {0}")]
XmlParse(String),
/// FontError.
#[error("font error: {0}")]
FontError(String),
/// LayoutError.
#[error("layout error: {0}")]
LayoutError(String),
/// LayoutFailed.
#[error("layout failed: {0}")]
LayoutFailed(String),
/// ParseFailed.
#[error("XML parse failed: {0}")]
ParseFailed(String),
/// FormCalcError.
#[error("FormCalc error: {0}")]
FormCalcError(String),
/// Io.
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
// ---- New structured variants (XFA-F9-01 #1120) ----
/// XFA packet extraction failed (e.g. missing /AcroForm, corrupt stream).
#[error("XFA extraction failed: {0}")]
ExtractionFailed(String),
/// Template XML could not be parsed.
#[error("Template parse error: {0}")]
TemplateParse(String),
/// Data binding from datasets to template failed.
#[error("Data binding failed: {0}")]
BindingFailed(String),
/// LayoutFailedAt.
/// LayoutFailedAt.
/// Layout failed at a specific pipeline stage.
///
/// Use this variant when you can identify which stage (e.g. "paginate",
/// "split", "occur") caused the failure so callers can give better
/// diagnostics.
#[error("Layout failed at {stage}: {reason}")]
LayoutFailedAt {
/// Pipeline stage where layout failed.
stage: String,
/// Reason for the failure.
reason: String,
},
/// PDF content stream generation failed.
#[error("Render failed: {0}")]
RenderFailed(String),
/// Final PDF serialisation / flatten step failed.
#[error("Flatten failed: {0}")]
FlattenFailed(String),
/// Feature is intentionally unsupported by the non-interactive XFA engine.
#[error("unsupported feature: {0}")]
UnsupportedFeature(String),
}
/// Result.
pub type Result<T> = std::result::Result<T, XfaError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn error_message_extraction_failed() {
let e = XfaError::ExtractionFailed("no /AcroForm key".to_string());
assert_eq!(format!("{e}"), "XFA extraction failed: no /AcroForm key");
}
#[test]
fn error_message_layout_failed_at() {
let e = XfaError::LayoutFailedAt {
stage: "paginate".to_string(),
reason: "zero-height page area".to_string(),
};
assert_eq!(
format!("{e}"),
"Layout failed at paginate: zero-height page area"
);
}
}