#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Error {
Parse(String, u32),
Unsupported(String),
}
impl Error {
pub fn into_message(self, selector: &str) -> String {
match self {
Error::Parse(detail, column) => {
let caret_pos = (column as usize).saturating_sub(1).min(selector.len());
let caret_line = format!("{}{}", " ".repeat(caret_pos), "^");
format!(
"Unable to parse the CSS selector {selector:?}: {detail}\n |\n | {selector}\n | {caret_line}"
)
}
Error::Unsupported(construct) => format!(
"The CSS selector {selector:?} uses {construct}, which this translator does not support"
),
}
}
}