From 86b03d625aa0c15b8d57b33975e8c6d9228f4062 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Thu, 11 Jul 2024 07:30:26 +0200 Subject: [PATCH] fix: Better error handling for protocol display --- matchbox_protocol/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matchbox_protocol/src/lib.rs b/matchbox_protocol/src/lib.rs index 9bf180df..30e14def 100644 --- a/matchbox_protocol/src/lib.rs +++ b/matchbox_protocol/src/lib.rs @@ -39,7 +39,7 @@ cfg_if! { impl fmt::Display for JsonPeerRequest { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", serde_json::to_string(self).expect("error serializing message")) + write!(f, "{}", serde_json::to_string(self).map_err(|_| fmt::Error)?) } } impl std::str::FromStr for JsonPeerRequest { @@ -52,7 +52,7 @@ cfg_if! { impl fmt::Display for JsonPeerEvent { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", serde_json::to_string(self).expect("error serializing message")) + write!(f, "{}", serde_json::to_string(self).map_err(|_| fmt::Error)?) } } impl std::str::FromStr for JsonPeerEvent {