From 9322b3d07e39c0c3bbd1b63ef225b7a17f7b337d Mon Sep 17 00:00:00 2001 From: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> Date: Tue, 8 Aug 2023 17:36:14 -0600 Subject: [PATCH] be resilient to bad lshw output (#2390) --- backend/src/util/lshw.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/src/util/lshw.rs b/backend/src/util/lshw.rs index 4de4bf46e..dd260f644 100644 --- a/backend/src/util/lshw.rs +++ b/backend/src/util/lshw.rs @@ -44,6 +44,20 @@ pub async fn lshw() -> Result, Error> { for class in KNOWN_CLASSES { cmd.arg("-class").arg(*class); } - serde_json::from_slice(&cmd.invoke(crate::ErrorKind::Lshw).await?) - .with_kind(crate::ErrorKind::Deserialization) + Ok( + serde_json::from_slice::>( + &cmd.invoke(crate::ErrorKind::Lshw).await?, + ) + .with_kind(crate::ErrorKind::Deserialization)? + .into_iter() + .filter_map(|v| match serde_json::from_value(v) { + Ok(a) => Some(a), + Err(e) => { + tracing::error!("Failed to parse lshw output: {e}"); + tracing::debug!("{e:?}"); + None + } + }) + .collect(), + ) }