Skip to main content

pdfboss_core/
error.rs

1//! Error and result types shared across all pdfboss crates.
2
3/// Convenience alias used throughout pdfboss.
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// All errors surfaced by pdfboss.
7///
8/// Parsing is lenient by design; hard errors are reserved for unreadable
9/// cross-reference data (after recovery), encryption, and I/O.
10#[derive(Debug, thiserror::Error)]
11pub enum Error {
12    #[error("i/o error: {0}")]
13    Io(#[from] std::io::Error),
14    #[error("syntax error at byte {offset}: {msg}")]
15    Syntax { offset: usize, msg: String },
16    #[error("invalid or unrecoverable cross-reference data")]
17    InvalidXref,
18    #[error("object {0} {1} not found")]
19    ObjectNotFound(u32, u16),
20    #[error("missing required key /{0}")]
21    MissingKey(&'static str),
22    #[error("type mismatch: expected {expected}, found {found}")]
23    TypeMismatch {
24        expected: &'static str,
25        found: &'static str,
26    },
27    #[error("unsupported filter /{0}")]
28    UnsupportedFilter(String),
29    #[error("stream decode failed: {0}")]
30    Decode(String),
31    #[error("encrypted documents are not supported")]
32    Encrypted,
33    #[error("page index {0} out of bounds ({1} pages)")]
34    PageNotFound(usize, usize),
35    #[error("circular reference involving object {0}")]
36    CircularReference(u32),
37    #[error("{0}")]
38    Other(String),
39}