rpdfium-doc 7676.6.4

Document-level features for rpdfium
Documentation
//! Error types for the rpdfium-doc crate.

use thiserror::Error;

/// Errors that can occur during document structure parsing.
#[derive(Debug, Clone, Error)]
pub enum DocError {
    /// A required dictionary key is missing.
    #[error("missing required key: {0}")]
    MissingKey(String),
    /// An object had an unexpected type.
    #[error("unexpected object type")]
    UnexpectedType,
    /// An error propagated from the parser layer.
    #[error("parser error: {0}")]
    Parser(String),
    /// A tree or linked-list traversal exceeded the maximum allowed depth.
    #[error("tree depth exceeded")]
    DepthExceeded,
    /// The provided value exceeds the field's maximum length.
    #[error("value too long: length {len} exceeds max {max}")]
    ValueTooLong {
        /// Actual length of the value.
        len: usize,
        /// Maximum allowed length.
        max: u32,
    },
    /// The provided value is not valid for the target field type.
    #[error("type mismatch: expected {expected}, got {got}")]
    TypeMismatch {
        /// The expected value kind.
        expected: String,
        /// The actual value kind.
        got: String,
    },
    /// A choice index is out of range.
    #[error("invalid choice index: {index} (field has {count} options)")]
    InvalidChoiceIndex {
        /// The requested index.
        index: usize,
        /// The number of available options.
        count: usize,
    },
    /// The named field was not found in the form.
    #[error("field not found: {0}")]
    FieldNotFound(String),
    /// An index was out of range.
    #[error("index out of range: {0}")]
    InvalidIndex(usize),
    /// The requested named entry was not found.
    #[error("not found: {0}")]
    NotFound(String),
    /// The requested operation is not supported.
    ///
    /// # Not Supported
    ///
    /// Returned by mutation APIs that are intentionally stubbed out because
    /// rpdfium is a read-only library (per ADR-017). The contained string
    /// describes the unsupported operation.
    #[error("not supported: {0}")]
    NotSupported(String),
}

/// Convenience result alias for [`DocError`].
pub type DocResult<T> = std::result::Result<T, DocError>;