use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum PdfError {
#[error("not a PDF file (missing %PDF header)")]
NotAPdf,
#[error("unsupported PDF version: {0}")]
UnsupportedVersion(String),
#[error("startxref not found")]
NoStartXref,
#[error("malformed xref table at offset {0}")]
MalformedXref(usize),
#[error("malformed trailer dictionary")]
MalformedTrailer,
#[error("object {obj_num} {gen_num} not found")]
ObjectNotFound { obj_num: u32, gen_num: u16 },
#[error("unexpected token: expected {expected}, got {got}")]
UnexpectedToken { expected: String, got: String },
#[error("unterminated {0}")]
Unterminated(&'static str),
#[error("invalid object at offset {0}")]
InvalidObject(usize),
#[error("stream missing /Length")]
StreamMissingLength,
#[error("unsupported filter: {0}")]
UnsupportedFilter(String),
#[error("decompression error: {0}")]
DecompressionError(String),
#[error("missing required key /{0} in dictionary")]
MissingKey(&'static str),
#[error("type mismatch: expected {expected} for /{key}")]
TypeMismatch { key: String, expected: &'static str },
#[error("page index {0} out of range (document has {1} pages)")]
PageOutOfRange(usize, usize),
#[error("circular reference detected for object {0} {1}")]
CircularReference(u32, u16),
#[error("{context} nesting exceeded the limit of {limit}")]
NestingTooDeep {
context: &'static str,
limit: u32,
},
#[error("PDF requires a password")]
PasswordRequired,
#[error("{0}")]
Other(String),
}