diff --git a/src/main.rs b/src/main.rs index a3cf3c2..e5554d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1262,7 +1262,7 @@ fn run_capture_pipeline( capture_result?; if let Some(err) = pipe.aggregator.take_fatal_error() { - return Err(std::io::Error::new(std::io::ErrorKind::Other, err).into()); + return Err(std::io::Error::other(err).into()); } // Print summary diff --git a/src/pipeline/aggregator.rs b/src/pipeline/aggregator.rs index 845dfa8..e63db43 100644 --- a/src/pipeline/aggregator.rs +++ b/src/pipeline/aggregator.rs @@ -305,10 +305,10 @@ fn handle_event( output_sinks: &mut OutputSinks, mode: DrainMode, ) -> Result<(), std::io::Error> { - if let DrainMode::ShutdownOnly = mode { - if !matches!(event, WorkerEvent::Shutdown(_)) { - return Ok(()); - } + if let DrainMode::ShutdownOnly = mode + && !matches!(event, WorkerEvent::Shutdown(_)) + { + return Ok(()); } match event { diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index f57d3bb..aedc9a8 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -239,6 +239,12 @@ pub struct VlanStack { truncated: bool, } +impl Default for VlanStack { + fn default() -> Self { + Self::new() + } +} + impl VlanStack { pub fn new() -> Self { Self { diff --git a/src/sinks.rs b/src/sinks.rs index 9818785..b73cc81 100644 --- a/src/sinks.rs +++ b/src/sinks.rs @@ -72,11 +72,9 @@ impl ExpiredFlowSinks { break; } } - if !disable_jsonl { - if let Err(err) = sink.flush() { - tracing::warn!(error = %err, "expired flows jsonl disabled after flush error"); - disable_jsonl = true; - } + if !disable_jsonl && let Err(err) = sink.flush() { + tracing::warn!(error = %err, "expired flows jsonl disabled after flush error"); + disable_jsonl = true; } } if disable_jsonl { @@ -92,11 +90,9 @@ impl ExpiredFlowSinks { break; } } - if !disable_csv { - if let Err(err) = sink.flush() { - tracing::warn!(error = %err, "expired flows csv disabled after flush error"); - disable_csv = true; - } + if !disable_csv && let Err(err) = sink.flush() { + tracing::warn!(error = %err, "expired flows csv disabled after flush error"); + disable_csv = true; } } if disable_csv { @@ -151,11 +147,11 @@ impl OutputSinks { description: &str, ) -> Result<(), std::io::Error> { let mut disable_alerts = false; - if let Some(sink) = self.alerts_jsonl.as_mut() { - if let Err(err) = sink.write_alert(ts, kind, description) { - tracing::warn!(error = %err, "alerts jsonl disabled after write error"); - disable_alerts = true; - } + if let Some(sink) = self.alerts_jsonl.as_mut() + && let Err(err) = sink.write_alert(ts, kind, description) + { + tracing::warn!(error = %err, "alerts jsonl disabled after write error"); + disable_alerts = true; } if disable_alerts { self.alerts_jsonl = None; @@ -171,10 +167,7 @@ impl OutputSinks { } } -fn open_optional_jsonl_sink( - path: Option<&Path>, - label: &str, -) -> Option { +fn open_optional_jsonl_sink(path: Option<&Path>, label: &str) -> Option { match path { Some(path) => match JsonlSink::new(path) { Ok(sink) => Some(sink), @@ -192,10 +185,7 @@ fn open_optional_jsonl_sink( } } -fn open_optional_csv_sink( - path: Option<&Path>, - label: &str, -) -> Option { +fn open_optional_csv_sink(path: Option<&Path>, label: &str) -> Option { match path { Some(path) => match ExpiredFlowCsvSink::new(path) { Ok(sink) => Some(sink), diff --git a/src/web/server.rs b/src/web/server.rs index 4a5778f..581c2c9 100644 --- a/src/web/server.rs +++ b/src/web/server.rs @@ -593,6 +593,7 @@ fn should_serve_spa(path: &str) -> bool { #[cfg(test)] mod tests { use super::*; + use crate::web::messages::StatsTick; use axum::{ body::Body, http::{Request, StatusCode, header}, @@ -601,7 +602,6 @@ mod tests { use std::time::Duration; use tokio_tungstenite::tungstenite::Message as WsMessage; use tower::util::ServiceExt; - use crate::web::messages::StatsTick; fn test_state(auth: Option) -> Arc { let (broadcast_tx, _) = broadcast::channel::(16); @@ -820,8 +820,7 @@ mod tests { WsMessage::Text(t) => t, other => panic!("unexpected: {other:?}"), }; - let hello_json: serde_json::Value = - serde_json::from_str(&hello_text).expect("hello json"); + let hello_json: serde_json::Value = serde_json::from_str(&hello_text).expect("hello json"); assert_eq!(hello_json["type"], "hello"); server_handle.abort(); @@ -933,7 +932,11 @@ mod tests { .await .expect("reconnect"); - let hello2 = socket2.next().await.expect("hello after reconnect").expect("msg"); + let hello2 = socket2 + .next() + .await + .expect("hello after reconnect") + .expect("msg"); let hello2_text = match hello2 { WsMessage::Text(t) => t, other => panic!("unexpected: {other:?}"),