Skip to main content

zpdf_core/
error.rs

1use crate::ObjectId;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, thiserror::Error)]
6pub enum Error {
7    #[error("not a PDF file")]
8    NotAPdf,
9
10    #[error("unsupported PDF version: {0}.{1}")]
11    UnsupportedVersion(u8, u8),
12
13    #[error("unexpected end of file at offset {0}")]
14    UnexpectedEof(u64),
15
16    #[error("invalid xref table at offset {0}")]
17    InvalidXref(u64),
18
19    #[error("object not found: {0}")]
20    ObjectNotFound(ObjectId),
21
22    #[error("type mismatch: expected {expected}, got {actual}")]
23    TypeMismatch {
24        expected: &'static str,
25        actual: &'static str,
26    },
27
28    #[error("missing required key: /{0}")]
29    MissingKey(String),
30
31    #[error("invalid object at offset {0}: {1}")]
32    InvalidObject(u64, String),
33
34    #[error("stream decode error: {0}")]
35    StreamDecode(String),
36
37    #[error("unsupported filter: {0}")]
38    UnsupportedFilter(String),
39
40    #[error("incorrect password for an encrypted document")]
41    WrongPassword,
42
43    #[error("recursion depth exceeded (max {0})")]
44    RecursionLimit(u32),
45
46    #[error("stream size exceeded (max {0} bytes)")]
47    StreamSizeLimit(u64),
48
49    #[error("string length exceeded (max {0} bytes)")]
50    StringLengthLimit(u32),
51
52    #[error("io error: {0}")]
53    Io(#[from] std::io::Error),
54}