Skip to main content

push_packet/rules/
error.rs

1#[non_exhaustive]
2#[allow(missing_docs)]
3#[derive(Debug, thiserror::Error)]
4pub enum RuleError {
5    #[error("each rule must have at least one constraint, such as cidr or port")]
6    MissingConstraint,
7    #[error("each rule must have an Action")]
8    MissingAction,
9    #[error("invalid IP address: {addr}")]
10    InvalidAddress {
11        addr: String,
12        #[source]
13        source: std::net::AddrParseError,
14    },
15    #[error("invalid CIDR range: {addr}")]
16    InvalidCidr {
17        addr: String,
18        #[source]
19        source: ipnet::AddrParseError,
20    },
21    #[error("a rule may not contain both ipv4 and ipv6 addresses")]
22    IncompatibleAddresses,
23}
24
25impl RuleError {
26    pub(crate) fn invalid_address(
27        addr: impl Into<String>,
28        source: std::net::AddrParseError,
29    ) -> Self {
30        let addr = addr.into();
31        Self::InvalidAddress { addr, source }
32    }
33
34    pub(crate) fn invalid_cidr(addr: impl Into<String>, source: ipnet::AddrParseError) -> Self {
35        let addr = addr.into();
36        Self::InvalidCidr { addr, source }
37    }
38}