use thiserror::Error;
#[derive(Debug, Error)]
pub enum XfaError {
#[error("failed to load PDF: {0}")]
LoadFailed(String),
#[error("XFA packet not found: {0}")]
PacketNotFound(String),
#[error("encrypted PDF: {0}")]
Encrypted(String),
#[error("XML parse error: {0}")]
XmlParse(String),
#[error("font error: {0}")]
FontError(String),
#[error("layout error: {0}")]
LayoutError(String),
#[error("layout failed: {0}")]
LayoutFailed(String),
#[error("XML parse failed: {0}")]
ParseFailed(String),
#[error("FormCalc error: {0}")]
FormCalcError(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("XFA extraction failed: {0}")]
ExtractionFailed(String),
#[error("Template parse error: {0}")]
TemplateParse(String),
#[error("Data binding failed: {0}")]
BindingFailed(String),
#[error("Layout failed at {stage}: {reason}")]
LayoutFailedAt { stage: String, reason: String },
#[error("Render failed: {0}")]
RenderFailed(String),
#[error("Flatten failed: {0}")]
FlattenFailed(String),
#[error("unsupported feature: {0}")]
UnsupportedFeature(String),
}
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"
);
}
}