1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, DonglerError>;
4
5#[derive(Debug, Error)]
6pub enum DonglerError {
7 #[error("unsupported or unknown document format for path: {path}")]
8 UnknownFormat { path: String },
9
10 #[error("{format} extraction is planned but not implemented yet")]
11 PlannedFormat { format: String },
12
13 #[error("invalid input: {0}")]
14 InvalidInput(String),
15
16 #[error("I/O error: {0}")]
17 Io(#[from] std::io::Error),
18
19 #[error("JSON error: {0}")]
20 Json(#[from] serde_json::Error),
21
22 #[error("PDF error: {0}")]
23 Pdf(String),
24
25 #[error("image error: {0}")]
26 Image(String),
27
28 #[error("archive error: {0}")]
29 Archive(String),
30}
31
32impl DonglerError {
33 pub fn planned_format(format: impl Into<String>) -> Self {
34 Self::PlannedFormat {
35 format: format.into(),
36 }
37 }
38
39 pub fn invalid_input(message: impl Into<String>) -> Self {
40 Self::InvalidInput(message.into())
41 }
42
43 pub fn pdf(message: impl Into<String>) -> Self {
44 Self::Pdf(message.into())
45 }
46
47 pub fn image(message: impl Into<String>) -> Self {
48 Self::Image(message.into())
49 }
50
51 pub fn archive(message: impl Into<String>) -> Self {
52 Self::Archive(message.into())
53 }
54}