Skip to main content

rpdfium_doc/
error.rs

1//! Error types for the rpdfium-doc crate.
2
3use thiserror::Error;
4
5/// Errors that can occur during document structure parsing.
6#[derive(Debug, Clone, Error)]
7pub enum DocError {
8    /// A required dictionary key is missing.
9    #[error("missing required key: {0}")]
10    MissingKey(String),
11    /// An object had an unexpected type.
12    #[error("unexpected object type")]
13    UnexpectedType,
14    /// An error propagated from the parser layer.
15    #[error("parser error: {0}")]
16    Parser(String),
17    /// A tree or linked-list traversal exceeded the maximum allowed depth.
18    #[error("tree depth exceeded")]
19    DepthExceeded,
20    /// The provided value exceeds the field's maximum length.
21    #[error("value too long: length {len} exceeds max {max}")]
22    ValueTooLong {
23        /// Actual length of the value.
24        len: usize,
25        /// Maximum allowed length.
26        max: u32,
27    },
28    /// The provided value is not valid for the target field type.
29    #[error("type mismatch: expected {expected}, got {got}")]
30    TypeMismatch {
31        /// The expected value kind.
32        expected: String,
33        /// The actual value kind.
34        got: String,
35    },
36    /// A choice index is out of range.
37    #[error("invalid choice index: {index} (field has {count} options)")]
38    InvalidChoiceIndex {
39        /// The requested index.
40        index: usize,
41        /// The number of available options.
42        count: usize,
43    },
44    /// The named field was not found in the form.
45    #[error("field not found: {0}")]
46    FieldNotFound(String),
47    /// An index was out of range.
48    #[error("index out of range: {0}")]
49    InvalidIndex(usize),
50    /// The requested named entry was not found.
51    #[error("not found: {0}")]
52    NotFound(String),
53    /// The requested operation is not supported.
54    ///
55    /// # Not Supported
56    ///
57    /// Returned by mutation APIs that are intentionally stubbed out because
58    /// rpdfium is a read-only library (per ADR-017). The contained string
59    /// describes the unsupported operation.
60    #[error("not supported: {0}")]
61    NotSupported(String),
62}
63
64/// Convenience result alias for [`DocError`].
65pub type DocResult<T> = std::result::Result<T, DocError>;