{"record":{"id":"c56d42ab160a9b97","repo":"GyulyVGC/sniffnet","slug":"sniffnet-error-at-file-line-e","errorCode":null,"errorMessage":"Sniffnet error at [{file}:{line}]: {e}","messagePattern":"Sniffnet error at \\[(.+?):(.+?)\\]: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utils/error_logger.rs","lineNumber":16,"sourceCode":"use std::fmt::Display;\n\n/// 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","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/GyulyVGC/sniffnet/blob/48b0575dc0d3c7e503a466a3cb2c1466ba600f8e/src/utils/error_logger.rs#L1-L34","documentation":"This is Sniffnet's central error-logging message, emitted by the ErrorLogger trait's log_err() implementation (src/utils/error_logger.rs:16). Whenever any Result<T, E: Display> returned by a fallible operation is chained with .log_err(crate::location!()) and holds an Err, this line prints 'Sniffnet error at [file:line]: e' to stderr and then returns the Result unchanged. It is a diagnostic log, not a crash: the application decides downstream whether to propagate, ignore, or display the error.","triggerScenarios":"Calling any pcap/networking API wrapped with .log_err(crate::location!()) that fails, e.g. truncating the log file in src/cli/mod.rs:45, waiting on the file-explorer child process in src/cli/mod.rs:47, reopening the log file in src/cli/mod.rs:57, or applying the 'less 2' pause filter in src/networking/types/capture_context.rs:158. The exact file:line in the message is the captured Location passed via the location!() macro, pointing at the call site, not at error_logger.rs itself.","commonSituations":"Running `cargo run` / debug builds where the very same log_err call sites also panic (see error 1); insufficient OS permissions for raw packet capture (non-root without CAP_NET_RAW on Linux, Windows without Npcap, macOS without privilege); a read-only or missing config/log directory when the CLI log file is truncated; the spawned file explorer process failing to exit or to be waited on.","solutions":["Read the full line: the [file:line] suffix identifies the exact failing call site — open that source location to see which operation failed.","Check capture privileges: on Linux run with sudo or `setcap cap_net_raw+ep` on the binary; on Windows install Npcap; on macOS allow the app in System Settings > Privacy & Security.","Verify the config/logs directory exists and is writable by the current user (confy's default config path, plus the Sniffnet log file path).","Re-run with `RUST_LOG`/release binary if the debug-mode panic (error 1) fires immediately after this log line and masks the diagnosis.","If the error string is a pcap error (e.g. 'no such device', 'permissions problem'), fix the adapter selection or pcap runtime before touching app code."],"exampleFix":"// before (fire-and-forget, error only logged via log_err and then dropped)\nlet _ = explorer.wait().log_err(crate::location!());\n\n// after (inspect the failure instead of only logging it)\nif let Err(e) = explorer.wait() {\n    eprintln!(\"failed to wait on file explorer: {e}\");\n}\n// or keep log_err but handle the returned Result explicitly:\nlet status = explorer.wait().log_err(crate::location!());","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// log_err returns the Result unchanged — always inspect it instead of discarding\nmatch risky_op().log_err(crate::location!()) {\n    Ok(v) => use_value(v),\n    Err(e) => {\n        // e already printed as \"Sniffnet error at [file:line]: {e}\"\n        recover_or_show_in_gui(e);\n    }\n}","preventionTips":["Treat every 'Sniffnet error at [...]' stderr line as the root-cause record; the [file:line] points to the failing call site.","Keep log_err call sites on operations that are safe to continue past; use hard error paths (CaptureContext::Error) for capture-critical failures.","Ensure the process has capture privileges and writable config/log paths before startup so log_err sites stay on the Ok path.","In CI, capture stderr and fail on 'Sniffnet error at' lines to detect regressions in debug test runs."],"tags":["rust","sniffnet","error-logging","stderr","diagnostics"],"backgroundTag":null,"analyzedSha":"48b0575dc0d3c7e503a466a3cb2c1466ba600f8e","analyzedAt":"2026-08-16T09:14:10.427Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}