web_scrape/scrape/
error.rsuse std::fmt::{Display, Formatter};
use clerr::Report;
#[derive(Debug)]
pub enum Error {
InvalidSelection { selection: String, message: String },
ExpectedOneGotMultiple { selection: String },
ExpectedOneGotNone { selection: String },
ExpectedOptionalGotMultiple { selection: String },
Generic(Report),
Other(String)
}
impl From<Report> for Error {
fn from(report: Report) -> Self {
Self::Generic(report)
}
}
impl From<String> for Error {
fn from(s: String) -> Self {
Self::Other(s)
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::InvalidSelection { selection, message } => {
write!(f, "invalid selection '{}': {}", selection, message)
}
Self::ExpectedOneGotMultiple { selection } => {
write!(f, "expected one, got multiple: {}", selection)
}
Self::ExpectedOneGotNone { selection } => {
write!(f, "expected one, got none: {}", selection)
}
Self::ExpectedOptionalGotMultiple { selection } => {
write!(f, "expected one or none, got multiple: {}", selection)
}
Self::Generic(report) => {
write!(f, "{}", report)
}
Self::Other(s) => {
write!(f, "{}", s)
}
}
}
}
impl std::error::Error for Error {}