1#[derive(thiserror::Error, Debug)]
3pub enum Error {
4 #[error("{0}")]
6 Json(String),
7
8 #[error("error in '{name}' fetcher: {error}")]
10 Fetcher { name: String, error: String },
11
12 #[error("error in '{fetcher}' matcher: {error}")]
14 Matcher { fetcher: String, error: String },
15
16 #[error("unknown operator '{0}'")]
18 UnknownOperator(String),
19
20 #[error("error in '{name}' operator: {error}")]
22 Operator { name: String, error: String },
23
24 #[error(transparent)]
25 Regex(#[from] regex::Error),
26
27 #[error(transparent)]
28 IpAddress(#[from] std::net::AddrParseError),
29
30 #[error(transparent)]
31 IpSubnet(#[from] ipnet::AddrParseError),
32}
33
34impl Error {
35 pub(crate) fn json(error: impl ToString) -> Self {
36 Error::Json(error.to_string())
37 }
38
39 pub(crate) fn fetcher(name: &str, error: impl ToString) -> Self {
40 Error::Fetcher {
41 name: name.to_string(),
42 error: error.to_string(),
43 }
44 }
45
46 pub(crate) fn matcher(fetcher: &str, error: impl ToString) -> Self {
47 Error::Matcher {
48 fetcher: fetcher.to_string(),
49 error: error.to_string(),
50 }
51 }
52
53 pub(crate) fn operator(name: &str, error: impl ToString) -> Self {
54 Error::Operator {
55 name: name.to_string(),
56 error: error.to_string(),
57 }
58 }
59}