From 5bb5e37e0709174a870355e44891a939199809b8 Mon Sep 17 00:00:00 2001 From: nutcas3 Date: Sat, 25 Apr 2026 05:52:57 +0300 Subject: [PATCH] feat: Add eBPF error types with recoverability classification for packet gateway - Add EbpfError enum with LoadError, AttachError, MapNotFound, MapAccessError, RedisSyncError, RedisFetchError, NotAttached, Timeout, and InvalidData variants - Add is_recoverable method returning true for MapAccessError, RedisSyncError, RedisFetchError, and Timeout errors - Add thiserror::Error derive for automatic error trait implementation - Add interface and map_name fields to AttachError and MapAccessError variants --- apps/packet-gateway/src/ebpf_error.rs | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 apps/packet-gateway/src/ebpf_error.rs diff --git a/apps/packet-gateway/src/ebpf_error.rs b/apps/packet-gateway/src/ebpf_error.rs new file mode 100644 index 0000000..edf3836 --- /dev/null +++ b/apps/packet-gateway/src/ebpf_error.rs @@ -0,0 +1,43 @@ +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum EbpfError { + #[error("Failed to load eBPF program: {0}")] + LoadError(String), + + #[error("Failed to attach XDP program to interface {interface}: {message}")] + AttachError { interface: String, message: String }, + + #[error("eBPF map '{map_name}' not found")] + MapNotFound { map_name: String }, + + #[error("Failed to access eBPF map '{map_name}': {message}")] + MapAccessError { map_name: String, message: String }, + + #[error("Failed to sync data to Redis: {0}")] + RedisSyncError(String), + + #[error("Failed to sync data from Redis: {0}")] + RedisFetchError(String), + + #[error("eBPF program detached or not attached")] + NotAttached, + + #[error("eBPF operation timeout: {0}")] + Timeout(String), + + #[error("Invalid eBPF data: {0}")] + InvalidData(String), +} + +impl EbpfError { + pub fn is_recoverable(&self) -> bool { + match self { + EbpfError::MapAccessError { .. } => true, + EbpfError::RedisSyncError(_) => true, + EbpfError::RedisFetchError(_) => true, + EbpfError::Timeout(_) => true, + _ => false, + } + } +}