1use std::fmt;
2
3#[derive(Debug)]
5pub enum Error {
6 Fetch(String),
8 Html(String),
10 Markdown(String),
12 Output(String),
14 Other(String),
16}
17
18impl std::error::Error for Error {}
19
20impl fmt::Display for Error {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 match self {
23 Error::Fetch(msg) => write!(f, "Failed to fetch URL: {}", msg),
24 Error::Html(msg) => write!(f, "Failed to process HTML: {}", msg),
25 Error::Markdown(msg) => write!(f, "Failed to convert to Markdown: {}", msg),
26 Error::Output(msg) => write!(f, "Failed to write output: {}", msg),
27 Error::Other(msg) => write!(f, "{}", msg),
28 }
29 }
30}
31
32impl From<reqwest::Error> for Error {
33 fn from(err: reqwest::Error) -> Self {
34 Error::Fetch(err.to_string())
35 }
36}
37
38impl From<std::io::Error> for Error {
39 fn from(err: std::io::Error) -> Self {
40 Error::Output(err.to_string())
41 }
42}
43
44impl From<anyhow::Error> for Error {
45 fn from(err: anyhow::Error) -> Self {
46 Error::Other(err.to_string())
47 }
48}