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