pdf_docx/error.rs
1//! Error types for PDF → DOCX conversion.
2
3use thiserror::Error;
4
5/// Errors returned by `pdf-docx` while converting a PDF to a DOCX
6/// (Office Open XML WordprocessingML) document.
7///
8/// All variants except [`Other`](Self::Other) wrap an underlying error
9/// from a more specific layer (PDF parsing, text extraction, XML, ZIP, I/O).
10/// Surface the inner cause when reporting the failure.
11#[derive(Debug, Error)]
12pub enum DocxError {
13 /// The source PDF could not be parsed before conversion could begin.
14 #[error("PDF error: {0}")]
15 Pdf(#[from] lopdf::Error),
16
17 /// Text or layout extraction from the source PDF failed.
18 #[error("extraction error: {0}")]
19 Extract(#[from] pdf_extract::ExtractError),
20
21 /// Building the DOCX `document.xml` body failed (malformed text run,
22 /// invalid attribute, encoding error in the XML serializer).
23 #[error("XML error: {0}")]
24 Xml(#[from] quick_xml::Error),
25
26 /// Packaging the DOCX archive failed (ZIP central directory error,
27 /// invalid entry name, compression failure).
28 #[error("ZIP error: {0}")]
29 Zip(#[from] zip::result::ZipError),
30
31 /// An I/O error while reading the source PDF or writing the DOCX
32 /// archive.
33 #[error("I/O error: {0}")]
34 Io(#[from] std::io::Error),
35
36 /// A non-categorised conversion failure. Reserved for cases the more
37 /// specific variants do not cover; the message describes the situation.
38 #[error("{0}")]
39 Other(String),
40}
41
42/// Convenience `Result` alias for fallible `pdf-docx` operations.
43pub type Result<T> = std::result::Result<T, DocxError>;