Skip to main content

pcap_toolkit/
error.rs

1//! Custom error types for pcap-toolkit library code.
2
3use thiserror::Error;
4
5/// Errors produced by the PCAP reader.
6#[derive(Debug, Error)]
7pub enum PcapError {
8    #[error("I/O error: {0}")]
9    Io(#[from] std::io::Error),
10
11    #[error("PCAP parse error: {0}")]
12    Parse(String),
13
14    #[error("unsupported link type: {0}")]
15    UnsupportedLinkType(u32),
16}
17
18/// Errors produced by the config loader.
19#[derive(Debug, Error)]
20pub enum ConfigError {
21    #[error("I/O error reading config: {0}")]
22    Io(#[from] std::io::Error),
23
24    #[error("TOML parse error: {0}")]
25    Toml(toml_span::DeserError),
26}
27
28impl From<toml_span::DeserError> for ConfigError {
29    fn from(e: toml_span::DeserError) -> Self {
30        ConfigError::Toml(e)
31    }
32}
33
34impl From<toml_span::Error> for ConfigError {
35    fn from(e: toml_span::Error) -> Self {
36        ConfigError::Toml(toml_span::DeserError::from(e))
37    }
38}
39
40/// Errors produced by the structured data exporter.
41#[derive(Debug, Error)]
42pub enum ExportError {
43    #[error("I/O error: {0}")]
44    Io(#[from] std::io::Error),
45
46    #[error("PCAP parse error: {0}")]
47    Parse(String),
48
49    #[error("JSON serialisation error: {0}")]
50    Json(String),
51
52    #[error("Parquet error: {0}")]
53    Parquet(String),
54
55    #[error("Avro error: {0}")]
56    Avro(String),
57
58    #[error("unsupported export format '{0}': expected json, parquet, or avro")]
59    UnknownFormat(String),
60
61    #[error("export producer thread panicked unexpectedly")]
62    ThreadPanic,
63}
64
65/// Errors produced by the live replay engine.
66#[derive(Debug, Error)]
67pub enum ReplayError {
68    #[error("I/O error: {0}")]
69    Io(#[from] std::io::Error),
70
71    #[error("permission denied: {0}")]
72    PermissionDenied(String),
73
74    #[error("unknown interface '{0}': not found in /sys/class/net/")]
75    UnknownInterface(String),
76
77    #[error("PCAP parse error: {0}")]
78    PcapParse(String),
79
80    #[error("live replay is not supported on this platform (Linux only)")]
81    NotSupported,
82}
83
84/// Errors produced by the two-pass sorter.
85#[derive(Debug, Error)]
86pub enum SortError {
87    #[error("I/O error: {0}")]
88    Io(#[from] std::io::Error),
89
90    #[error("PCAP parse error: {0}")]
91    Parse(String),
92
93    #[error("PCAPng input is not supported for sorting; use `info` or `stats` instead")]
94    PcapNgNotSupported,
95
96    #[error("invalid slice duration '{0}': expected e.g. '1h', '30m', '1d', or seconds")]
97    InvalidSlice(String),
98
99    #[error(
100        "incompatible link types: first file uses {first}, \
101         file '{path}' uses {found} — all inputs must share the same link type"
102    )]
103    IncompatibleLinkType {
104        path: std::path::PathBuf,
105        first: i32,
106        found: i32,
107    },
108}