From d715b452c196240f1eaa4742bd2133b8f77ca683 Mon Sep 17 00:00:00 2001 From: Gilles Soulier Date: Sat, 23 May 2026 13:11:10 +0200 Subject: [PATCH] =?UTF-8?q?fix(smart=20v0.1.13):=20SmartTemp.current=20opt?= =?UTF-8?q?ionnel=20=E2=80=94=20=C3=A9vite=20=C3=A9chec=20parse=20JSON?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Certains NVMe (ASUS TUF A16) ont un champ temperature sans current. Le champ requis current: i64 faisait crasher toute la désérialisation. Correction : #[serde(default)] + and_then au lieu de map. Co-Authored-By: Claude Sonnet 4.6 --- agent/Cargo.lock | 2 +- agent/Cargo.toml | 2 +- agent/src/metrics/smart.rs | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/agent/Cargo.lock b/agent/Cargo.lock index ab45763..de21580 100644 --- a/agent/Cargo.lock +++ b/agent/Cargo.lock @@ -248,7 +248,7 @@ dependencies = [ [[package]] name = "nanometrics-agent" -version = "0.1.12" +version = "0.1.13" dependencies = [ "libc", "rumqttc", diff --git a/agent/Cargo.toml b/agent/Cargo.toml index 380590d..4fd6e1a 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nanometrics-agent" -version = "0.1.12" +version = "0.1.13" edition = "2021" [lib] diff --git a/agent/src/metrics/smart.rs b/agent/src/metrics/smart.rs index 6f3e780..e994789 100644 --- a/agent/src/metrics/smart.rs +++ b/agent/src/metrics/smart.rs @@ -12,7 +12,10 @@ struct SmartJson { struct SmartStatus { passed: bool } #[derive(Deserialize)] -struct SmartTemp { current: i64 } +struct SmartTemp { + #[serde(default)] + current: Option, +} #[derive(Deserialize)] struct SmartAttrs { table: Vec } @@ -44,7 +47,7 @@ pub fn is_available() -> bool { pub fn parse_json(json: &str) -> Result { let s: SmartJson = serde_json::from_str(json)?; - let temperature = s.temperature.as_ref().map(|t| t.current) + let temperature = s.temperature.as_ref().and_then(|t| t.current) .or_else(|| s.nvme_smart_health_information_log.as_ref()?.temperature); let mut reallocated = None;