From bbd12e201e05fca30696a3f8cc2dda70abe80bc4 Mon Sep 17 00:00:00 2001 From: Darius Maitia Date: Mon, 27 Nov 2023 15:53:30 +0100 Subject: [PATCH] Sifting plugin private fields on debug logs. (#592) --- commons/zenoh-config/src/lib.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/commons/zenoh-config/src/lib.rs b/commons/zenoh-config/src/lib.rs index 9c07bd16e7..53ac033506 100644 --- a/commons/zenoh-config/src/lib.rs +++ b/commons/zenoh-config/src/lib.rs @@ -623,9 +623,15 @@ impl Config { impl std::fmt::Display for Config { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut json = serde_json::to_value(self).unwrap(); - sift_privates(&mut json); - write!(f, "{json}") + serde_json::to_value(self) + .map(|mut json| { + sift_privates(&mut json); + write!(f, "{json}") + }) + .map_err(|e| { + _ = write!(f, "{e:?}"); + fmt::Error + })? } } @@ -1030,9 +1036,12 @@ impl<'a> serde::Deserialize<'a> for PluginsConfig { }) } } + impl std::fmt::Debug for PluginsConfig { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", &self.values) + let mut values: Value = self.values.clone(); + sift_privates(&mut values); + write!(f, "{:?}", values) } }