Skip to main content

pdfrum_object/
error.rs

1//! Failures the object layer can report.
2
3use crate::ObjRef;
4
5/// What can go wrong constructing or resolving PDF objects.
6///
7/// Deliberately short: almost everything in this crate is total. A typed
8/// accessor never errors — a wrong type or a broken reference is *absence*
9/// (`None`, or the type's fallback value), and the store records the
10/// underlying failure in its `Diagnostics`.
11#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
12#[non_exhaustive]
13pub enum Error {
14    /// The store has no object under this reference: the cross-reference
15    /// entry is free, missing, or the object body failed to parse.
16    #[error("no object for reference {}:{}", .0.num, .0.generation)]
17    UnresolvedRef(ObjRef),
18
19    /// Fetching this reference re-entered a fetch already in progress
20    /// (an object whose body refers to itself, directly or through `/Length`).
21    #[error("reference cycle while fetching {}:{}", .0.num, .0.generation)]
22    RefLoop(ObjRef),
23
24    /// A byte span was asked for a range outside its backing buffer.
25    #[error("span range {start}..{end} is outside a buffer of {len} bytes")]
26    SpanOutOfBounds {
27        /// Start of the requested range.
28        start: usize,
29        /// End of the requested range.
30        end: usize,
31        /// Length of the backing buffer.
32        len: usize,
33    },
34}