Skip to main content

rpdfium_edit/
error.rs

1// Derived from PDFium's core/fpdfapi/edit/ error handling
2// Original: Copyright 2014 The PDFium Authors
3// Licensed under BSD-3-Clause / Apache-2.0
4// See pdfium-upstream/LICENSE for the original license.
5
6//! Error types for the rpdfium-edit crate.
7
8use rpdfium_core::error::PdfError;
9use rpdfium_doc::DocError;
10use rpdfium_parser::object::ObjectId;
11
12/// Errors from PDF editing and writing operations.
13#[derive(Debug, thiserror::Error)]
14pub enum EditError {
15    /// An error from the PDF parser layer.
16    #[error(transparent)]
17    Parse(#[from] PdfError),
18
19    /// An error from the document structure layer.
20    #[error(transparent)]
21    Doc(#[from] DocError),
22
23    /// An I/O error during writing.
24    #[error(transparent)]
25    Io(#[from] std::io::Error),
26
27    /// Page index out of range.
28    #[error("page index out of range: {index} (document has {count} pages)")]
29    PageOutOfRange {
30        /// The requested page index.
31        index: usize,
32        /// The total page count.
33        count: usize,
34    },
35
36    /// Annotation not found.
37    #[error("annotation not found: {0}")]
38    AnnotationNotFound(ObjectId),
39
40    /// Invalid page object index.
41    #[error("invalid page object index: {0}")]
42    InvalidObjectIndex(usize),
43
44    /// Form field not found.
45    #[error("field not found: {0}")]
46    FieldNotFound(String),
47
48    /// Encryption error.
49    #[error("encryption error: {0}")]
50    Encryption(String),
51
52    /// Operation not supported.
53    #[error("not supported: {0}")]
54    NotSupported(String),
55
56    /// Generic error.
57    #[error("{0}")]
58    Other(String),
59}
60
61/// Convenience result alias for [`EditError`].
62pub type EditResult<T> = std::result::Result<T, EditError>;