{"record":{"id":"5398d53ed9d24215","repo":"GyulyVGC/sniffnet","slug":"panic-bare-panic-triggered-by-errorlogger-on-e","errorCode":null,"errorMessage":"panic!() (bare panic triggered by ErrorLogger on Err in debug builds)","messagePattern":"panic!\\(\\) \\(bare panic triggered by ErrorLogger on Err in debug builds\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utils/error_logger.rs","lineNumber":21,"sourceCode":"/// Trait for logging errors in a unified way\npub trait ErrorLogger<T, E> {\n    /// Log the error and its location\n    #[allow(clippy::missing_errors_doc)]\n    fn log_err(self, loc: Location) -> Result<T, E>;\n}\n\nimpl<T, E: Display> ErrorLogger<T, E> for Result<T, E> {\n    #[allow(clippy::print_stderr)]\n    fn log_err(self, location: Location) -> Result<T, E> {\n        if let Err(e) = &self {\n            let file = location.file;\n            let line = location.line;\n            eprintln!(\"Sniffnet error at [{file}:{line}]: {e}\");\n            // in debug mode, panic on error\n            #[cfg(debug_assertions)]\n            #[allow(clippy::panic)]\n            {\n                panic!();\n            }\n        }\n\n        self\n    }\n}\n\n/// Struct to store the location in the code (file and line)\npub struct Location {\n    pub file: &'static str,\n    pub line: u32,\n}\n\n#[macro_export]\n/// Macro to get the current location in the code (file and line)\nmacro_rules! location {\n    () => {\n        Location {","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/GyulyVGC/sniffnet/blob/48b0575dc0d3c7e503a466a3cb2c1466ba600f8e/src/utils/error_logger.rs#L3-L39","documentation":"The ErrorLogger implementation intentionally panics on any Err when Sniffnet is compiled with debug assertions (src/utils/error_logger.rs:21). The panic is gated by #[cfg(debug_assertions)] and #[allow(clippy::panic)], so every error that flows through log_err() during development aborts immediately with a bare panic!() (empty panic message) right after the 'Sniffnet error at [...]' stderr line. This is a fail-fast developer aid: in release builds the same code only logs and continues.","triggerScenarios":"Any `.log_err(crate::location!())` call site returning Err while running a debug build: `cargo run`, `cargo run -- --restore-default`, `cargo test` exercising CLI paths (src/cli/mod.rs:45,47,57), or pausing a live capture (capture_context.rs:158). Because the panic message is empty, the only context is the stderr line printed just before the panic and the resulting backtrace.","commonSituations":"Developers running the app via `cargo run` without elevated privileges, so pcap open fails and log_err panics; CI test jobs compiled in debug mode that touch filesystem or capture code paths; contributors confused by a panic with no message — the real cause is always the preceding 'Sniffnet error at [file:line]: e' line.","solutions":["Look at the last stderr line before the panic ('Sniffnet error at [file:line]: <error>') — that is the actual failure; the panic is just the debug-mode amplifier.","Fix the underlying error (permissions, missing device/file, invalid path) identified by that line.","Run `cargo run --release` (or a packaged build) when you need the app to continue past recoverable errors.","Run with `RUST_BACKTRACE=1` to confirm which log_err call site panicked.","As a last resort for local debugging only, temporarily remove the #[cfg(debug_assertions)] panic block — do not ship that change."],"exampleFix":"// before — debug builds panic on every logged error\nif let Err(e) = &self {\n    eprintln!(\"Sniffnet error at [{file}:{line}]: {e}\");\n    #[cfg(debug_assertions)]\n    {\n        panic!();\n    }\n}\n\n// after — fail fast with context instead of a bare, message-less panic\n#[cfg(debug_assertions)]\n{\n    panic!(\"Sniffnet error at [{file}:{line}]: {e}\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// You cannot catch this panic portably (no catch_unwind around log_err in app code);\n// instead prevent the Err from reaching log_err in debug runs:\n#[cfg(debug_assertions)]\nif risky_capture_op().is_err() {\n    eprintln!(\"capture setup failed; run with privileges or pick another device\");\n    return;\n}\nrisky_capture_op().log_err(crate::location!());","preventionTips":["Never assume a bare panic in a debug run is a real bug — check the preceding 'Sniffnet error at' stderr line for the cause.","Run with RUST_BACKTRACE=1 to map the panic to its log_err call site.","Use `cargo run --release` when you need tolerant behavior during manual testing.","Give the dev binary capture privileges (setcap/sudo) so log_err sites don't fire at all."],"tags":["rust","sniffnet","panic","debug-builds","fail-fast"],"backgroundTag":null,"analyzedSha":"48b0575dc0d3c7e503a466a3cb2c1466ba600f8e","analyzedAt":"2026-08-16T09:14:10.427Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}