Skip to main content

netpulse/
error.rs

1// src/error.rs — Library-level error types for netpulse
2// Uses `thiserror` for ergonomic, typed errors at the library boundary.
3// The CLI layer wraps these with `anyhow` for context-rich display.
4
5use thiserror::Error;
6
7#[derive(Debug, Error)]
8pub enum NetPulseError {
9    #[error("socket error: {0}")]
10    SocketError(#[from] std::io::Error),
11
12    #[error("probe timed out after {timeout_ms}ms")]
13    Timeout { timeout_ms: u64 },
14
15    #[error("failed to parse probe response: {reason}")]
16    ParseError { reason: String },
17
18    #[error("invalid target address '{target}': {reason}")]
19    InvalidTarget { target: String, reason: String },
20
21    #[error("configuration error: {0}")]
22    ConfigError(String),
23
24    #[error("insufficient privileges — ICMP requires root or CAP_NET_RAW")]
25    InsufficientPrivileges,
26}