use thiserror::Error;
#[derive(Debug, Error, PartialEq, Eq, Clone)]
pub enum Error {
#[error("failed to parse the rest of input: ...'{0}'")]
Nom(String),
#[error("invalid date: {0}")]
InvalidDate(String),
#[error("query cannot start with 'not'; add any other queries before '{0}'")]
NotAtFirst(String),
#[error("unknown browser: '{0}'")]
BrowserNotFound(String),
#[error("unknown Electron version: {0}")]
UnknownElectronVersion(String),
#[error("unknown Node.js version: {0}")]
UnknownNodejsVersion(String),
#[error("unknown version '{1}' of browser '{0}'")]
UnknownBrowserVersion(String, String),
#[error("current environment for querying `current node` is not supported")]
UnsupportedCurrentNode,
#[error("current environment for querying `extends ...` is not supported")]
UnsupportedExtends,
#[error("unknown browser feature: '{0}'")]
UnknownBrowserFeature(String),
#[error("unknown region: '{0}'")]
UnknownRegion(String),
#[error("unknown browser query: '{0}'")]
UnknownQuery(String),
#[error("duplicated section '{0}' in config")]
DuplicatedSection(String),
#[error("failed to read config file: {0}")]
FailedToReadConfig(String),
#[error("missing 'browserslist' field in '{0}' file")]
MissingFieldInPkg(String),
#[error("duplicated: '{0}' directory contains both {1} and {2}.")]
DuplicatedConfig(String, &'static str, &'static str),
#[error("failed to access current working directory")]
FailedToAccessCurrentDir,
#[error("missing config for Browserslist environment '{0}'")]
MissingEnv(String),
#[error("invalid extend name: {0}")]
InvalidExtendName(&'static str),
#[error("failed to resolve '{0}' package in `extends` query")]
FailedToResolveExtend(String),
#[error("year overflow")]
YearOverflow,
}
impl<'a> From<nom::Err<nom::error::Error<&'a str>>> for Error {
fn from(e: nom::Err<nom::error::Error<&'a str>>) -> Self {
match e {
nom::Err::Error(e) | nom::Err::Failure(e) => Self::Nom(e.input.to_owned()),
_ => unreachable!(),
}
}
}