use std::fmt;
#[derive(Debug)]
pub enum Error {
Fetch(String),
Html(String),
Markdown(String),
Output(String),
Other(String),
}
impl std::error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Fetch(msg) => write!(f, "Failed to fetch URL: {}", msg),
Error::Html(msg) => write!(f, "Failed to process HTML: {}", msg),
Error::Markdown(msg) => write!(f, "Failed to convert to Markdown: {}", msg),
Error::Output(msg) => write!(f, "Failed to write output: {}", msg),
Error::Other(msg) => write!(f, "{}", msg),
}
}
}
impl From<reqwest::Error> for Error {
fn from(err: reqwest::Error) -> Self {
Error::Fetch(err.to_string())
}
}
impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self {
Error::Output(err.to_string())
}
}
impl From<anyhow::Error> for Error {
fn from(err: anyhow::Error) -> Self {
Error::Other(err.to_string())
}
}