Skip to main content

pdf_objects/
error.rs

1use std::error::Error;
2use std::fmt::{Display, Formatter};
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum PdfError {
6    Parse(String),
7    Corrupt(String),
8    Unsupported(String),
9    InvalidPageIndex(usize),
10    MissingObject(String),
11    UnsupportedOption(String),
12    InvalidPassword,
13}
14
15pub type PdfResult<T> = Result<T, PdfError>;
16
17impl Display for PdfError {
18    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
19        match self {
20            PdfError::Parse(message) => write!(f, "parse error: {message}"),
21            PdfError::Corrupt(message) => write!(f, "corrupt pdf: {message}"),
22            PdfError::Unsupported(message) => write!(f, "unsupported feature: {message}"),
23            PdfError::InvalidPageIndex(index) => write!(f, "invalid page index: {index}"),
24            PdfError::MissingObject(message) => write!(f, "missing object: {message}"),
25            PdfError::UnsupportedOption(message) => write!(f, "unsupported option: {message}"),
26            PdfError::InvalidPassword => write!(
27                f,
28                "invalid password: the supplied password does not authenticate as the user or owner password for this document"
29            ),
30        }
31    }
32}
33
34impl Error for PdfError {}