rama_haproxy/protocol/v2/
error.rs1use std::fmt;
4
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
7pub enum ParseError {
8 Incomplete(usize),
10 Prefix,
12 Version(u8),
14 Command(u8),
16 AddressFamily(u8),
18 Protocol(u8),
20 Partial(usize, usize),
22 InvalidAddresses(usize, usize),
24 InvalidTLV(u8, u16),
26 Leftovers(usize),
28}
29
30impl fmt::Display for ParseError {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 Self::Incomplete(len) => write!(f, "Expected header to the protocol prefix plus 4 bytes after the prefix (length {}).", len),
34 Self::Prefix => write!(f, "Expected header to start with a prefix of '\\r\\n\\r\\n\\0\\r\\nQUIT\\n'."),
35 Self::Version(version) => write!(f, "Expected version {:X} to be equal to 2.", version),
36 Self::Command(command) => write!(f, "Invalid command {:X}. Command must be one of: Local, Proxy.", command),
37 Self::AddressFamily(af) => write!(f, "Invalid Address Family {:X}. Address Family must be one of: Unspecified, IPv4, IPv6, Unix.", af),
38 Self::Protocol(protocol) => write!(f, "Invalid protocol {:X}. Protocol must be one of: Unspecified, Stream, or Datagram.", protocol),
39 Self::Partial(len, total) => write!(f, "Header does not contain the advertised length of the address information and TLVs (has {} out of {} bytes).", len, total),
40 Self::InvalidAddresses(len, total) => write!(f, "Header length of {} bytes cannot store the {} bytes required for the address family.", len, total),
41 Self::InvalidTLV(tlv, len) => write!(f, "Header is not long enough to contain TLV {} with length {}.", tlv, len),
42 Self::Leftovers(len) => write!(f, "Header contains leftover {} bytes not accounted for by the address family or TLVs.", len),
43 }
44 }
45}
46
47impl std::error::Error for ParseError {}