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 /// A transport-layer failure from an asynchronous byte source — an I/O
38 /// error, an HTTP failure, a refused range request, a short read.
39 ///
40 /// Carried as a rendered message so this crate stays free of transport
41 /// types. Produced when a source whose own error type is richer (the
42 /// asynchronous document's) crosses a shared-algorithm boundary that
43 /// speaks this `Result`; the adapter unwraps its parse-layer errors back
44 /// to the original variant and renders only the genuinely transport-level
45 /// remainder into this one.
46 #[error("transport: {0}")]
47 Transport(String),
48 /// The operating system's random source could not be read, carrying
49 /// the underlying `getrandom` error's rendered message. Raised by
50 /// [`crate::Encryptor::aes256`], the only caller that draws on it.
51 #[error("random source unavailable: {0}")]
52 RandomUnavailable(String),
53 #[error("{0}")]
54 Other(String),
55}