use std::{ops::Range, path::PathBuf};
use thiserror::Error as ErrorTrait;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(ErrorTrait, Debug)]
pub enum Error {
#[error("configuration file `{0}` not found ({1})")]
ConfigFileNotFound(PathBuf, std::io::Error),
#[error("bad configuration file: `{0}`")]
ConfigParsing(#[from] toml::de::Error),
#[error("error when converting the hexadecimal color `{0}` to rgb: {1:?}")]
HexToRgbConversion(String, String),
}
#[derive(ErrorTrait, Debug, PartialEq, Eq)]
pub enum ParseErrorKind<'a> {
#[error("the selector `{0}` is too short to be an existing selector")]
TooShort(&'a str),
#[error("the selector `{0}` has some variants but no modifier")]
VariantsWithoutModifier(&'a str),
#[error("no plugins found to handle the selector `{0}`")]
UnknownPlugin(&'a str),
#[error("the variant `{0}` of the selector `{1}` does not exist")]
UnknownVariant(&'a str, &'a str),
}
#[derive(Debug, PartialEq, Eq)]
pub struct ParseError<'a> {
pub span: Range<usize>,
pub kind: ParseErrorKind<'a>,
}
impl<'a> ParseError<'a> {
pub(crate) fn new(span: Range<usize>, kind: ParseErrorKind<'a>) -> Self {
Self { span, kind }
}
}