1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Html2PdfError>;
7
8#[derive(Error, Debug)]
10pub enum Html2PdfError {
11 #[error("Chrome browser error: {0}")]
13 ChromeError(String),
14
15 #[error("PDF error: {0}")]
17 PdfError(#[from] lopdf::Error),
18
19 #[error("IO error: {0}")]
21 IoError(#[from] std::io::Error),
22
23 #[error("Encryption error: {0}")]
25 EncryptionError(String),
26
27 #[error("Invalid input: {0}")]
29 InvalidInput(String),
30
31 #[error("Configuration error: {0}")]
33 ConfigError(String),
34
35 #[error("Operation timed out: {0}")]
37 TimeoutError(String),
38
39 #[error("Error: {0}")]
41 Other(#[from] anyhow::Error),
42}
43
44impl Html2PdfError {
45 pub fn chrome<S: Into<String>>(msg: S) -> Self {
47 Self::ChromeError(msg.into())
48 }
49
50 pub fn encryption<S: Into<String>>(msg: S) -> Self {
52 Self::EncryptionError(msg.into())
53 }
54
55 pub fn invalid_input<S: Into<String>>(msg: S) -> Self {
57 Self::InvalidInput(msg.into())
58 }
59
60 pub fn config<S: Into<String>>(msg: S) -> Self {
62 Self::ConfigError(msg.into())
63 }
64
65 pub fn timeout<S: Into<String>>(msg: S) -> Self {
67 Self::TimeoutError(msg.into())
68 }
69}
70
71