use css_cat::Error as CssError;
use html_cat::Error as HtmlError;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
Html(HtmlError),
Css(CssError),
InvalidSelector {
selector: String,
},
NodeNotFound {
id: u64,
},
NotAnElement {
id: u64,
},
AlreadyParented {
child: u64,
},
}
impl From<HtmlError> for Error {
fn from(value: HtmlError) -> Self {
Self::Html(value)
}
}
impl From<CssError> for Error {
fn from(value: CssError) -> Self {
Self::Css(value)
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Html(e) => write!(f, "html error: {e}"),
Self::Css(e) => write!(f, "css error: {e}"),
Self::InvalidSelector { selector } => {
write!(f, "invalid selector source: {selector:?}")
}
Self::NodeNotFound { id } => write!(f, "node id {id} not found"),
Self::NotAnElement { id } => write!(f, "node id {id} is not an element"),
Self::AlreadyParented { child } => {
write!(f, "node id {child} already has a parent")
}
}
}
}
impl std::error::Error for Error {}