Skip to main content

browserslist/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error, PartialEq, Eq, Clone)]
4/// The errors may occur when querying with browserslist.
5pub enum Error {
6    #[error("failed to parse the rest of input: ...'{0}'")]
7    /// Error of parsing query.
8    Parse(String),
9
10    #[error("invalid date: {0}")]
11    /// Date format is invalid.
12    InvalidDate(String),
13
14    #[error("query cannot start with 'not'; add any other queries before '{0}'")]
15    /// Query can't start with a negated query which starts with `not`.
16    NotAtFirst(String),
17
18    #[error("unknown browser: '{0}'")]
19    /// The given browser name can't be found.
20    BrowserNotFound(String),
21
22    #[error("unknown Electron version: {0}")]
23    /// The given Electron version can't be found.
24    UnknownElectronVersion(String),
25
26    #[error("unknown Node.js version: {0}")]
27    /// The given Node.js version can't be found.
28    UnknownNodejsVersion(String),
29
30    #[error("unknown version '{1}' of browser '{0}'")]
31    /// The given version of the given browser can't be found.
32    UnknownBrowserVersion(String, String),
33
34    #[error("current environment for querying `current node` is not supported")]
35    /// Current environment doesn't support querying `current node`,
36    /// for example, running this library on Non-Node.js platform or
37    /// no Node.js installed.
38    UnsupportedCurrentNode,
39
40    #[error("unknown browser feature: '{0}'")]
41    /// Unknown browser feature.
42    UnknownBrowserFeature(String),
43
44    #[error("unknown region: '{0}'")]
45    /// Unknown Can I Use region.
46    UnknownRegion(String),
47
48    #[error("unknown browser query: '{0}'")]
49    /// Query can't be recognized.
50    UnknownQuery(String),
51
52    #[error("year overflow")]
53    /// Year overflow.
54    YearOverflow,
55
56    #[error(
57        "Using newly available with a date is not supported, please use \"widely available on YYYY-MM-DD\" and add 30 months to the date you specified."
58    )]
59    /// Baseline Newly available cannot be queried on a date.
60    BaselineNewlyAvailableOnDate,
61}
62
63impl<'a> From<&'a str> for Error {
64    fn from(input: &'a str) -> Self {
65        Self::Parse(input.to_owned())
66    }
67}