Skip to content

Commit

Permalink
be resilient to bad lshw output (#2390)
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bonez committed Aug 8, 2023
1 parent 55f5329 commit 9322b3d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions backend/src/util/lshw.rs
Expand Up @@ -44,6 +44,20 @@ pub async fn lshw() -> Result<Vec<LshwDevice>, 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::<Vec<serde_json::Value>>(
&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(),
)
}

0 comments on commit 9322b3d

Please sign in to comment.