1use thiserror::Error;
12
13#[derive(Error, Debug)]
15pub enum Error {
16 #[error("PCAP error: {0}")]
18 Pcap(#[from] PcapError),
19
20 #[error("Protocol parse error: {0}")]
22 Protocol(#[from] ProtocolError),
23
24 #[error("I/O error: {0}")]
26 Io(#[from] std::io::Error),
27}
28
29#[derive(Error, Debug)]
31pub enum PcapError {
32 #[error("File not found: {path}")]
34 FileNotFound { path: String },
35
36 #[error("Invalid PCAP format: {reason}")]
38 InvalidFormat { reason: String },
39
40 #[error("Unsupported link type: {link_type}")]
42 UnsupportedLinkType { link_type: u16 },
43
44 #[error("Truncated packet at frame {frame}: expected {expected} bytes, got {actual}")]
46 TruncatedPacket {
47 frame: u64,
48 expected: usize,
49 actual: usize,
50 },
51}
52
53#[derive(Error, Debug)]
55pub enum ProtocolError {
56 #[error("{protocol}: packet too short (need {needed} bytes, have {have})")]
58 PacketTooShort {
59 protocol: &'static str,
60 needed: usize,
61 have: usize,
62 },
63
64 #[error("{protocol}: invalid {field}: {reason}")]
66 InvalidField {
67 protocol: &'static str,
68 field: &'static str,
69 reason: String,
70 },
71
72 #[error("{protocol}: checksum mismatch (expected {expected:#x}, got {actual:#x})")]
74 ChecksumMismatch {
75 protocol: &'static str,
76 expected: u16,
77 actual: u16,
78 },
79}
80
81pub type Result<T> = std::result::Result<T, Error>;