Skip to main content

pdf_forms/
error.rs

1use thiserror::Error;
2
3/// All errors returned by the pdf-forms public API.
4///
5/// `#[non_exhaustive]` allows adding variants in minor releases.
6#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum PdfError {
9    /// The PDF bytes could not be parsed.
10    #[error("PDF parse error: {0}")]
11    Parse(String),
12
13    /// The document could not be serialized to bytes.
14    #[error("PDF serialize error: {0}")]
15    Serialize(String),
16
17    /// A field name in the FieldMap was not found in the document's AcroForm.
18    #[error("invalid field '{name}': {reason}")]
19    InvalidField { name: String, reason: String },
20
21    /// An AcroForm field has a widget type not supported by pdf-forms.
22    #[error("unsupported widget type: {0}")]
23    UnsupportedWidget(String),
24
25    /// Image bytes could not be decoded.
26    #[error("image decode error: {0}")]
27    ImageDecode(String),
28
29    /// The requested page number does not exist in the document.
30    #[error("page {0} not found")]
31    PageNotFound(u32),
32
33    /// An internal lopdf operation failed.
34    #[error("internal PDF error: {0}")]
35    Internal(String),
36}
37
38impl From<crate::lopdf_error::Error> for PdfError {
39    fn from(e: crate::lopdf_error::Error) -> Self {
40        PdfError::Internal(e.to_string())
41    }
42}