From f3cb8f6eae5906904a34d234709a2c2d943f8f45 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Mon, 18 Mar 2024 13:22:02 -0700 Subject: [PATCH] fix: fmt::Display output for Status is now valid JSON Added a comma and newline in between fields Fixes https://dfinity.atlassian.net/browse/SDK-1457 --- CHANGELOG.md | 1 + ic-agent/src/agent/status.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59bf1367..dafacc5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added `FetchCanisterLogs` function to `MgmtMethod` and a corresponding wrapper to `ManagementCanister`. * Updated the `ring` crate to 0.17.7. `ring` 0.16 has a bug where it requires incorrect Ed25519 PEM encoding. 0.17.7 fixes that and is backwards compatible. * Removed serde and candid serialization traits from the `Status` type. +* Added commas and newlines to the `Status` fmt::Display output. It is valid JSON now (it was close before). ## [0.33.0] - 2024-02-08 diff --git a/ic-agent/src/agent/status.rs b/ic-agent/src/agent/status.rs index ef49be0b..60f78203 100644 --- a/ic-agent/src/agent/status.rs +++ b/ic-agent/src/agent/status.rs @@ -58,7 +58,13 @@ pub struct Status { impl std::fmt::Display for Status { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str("{\n")?; + let mut first = true; for (key, value) in &self.values { + if first { + first = false; + } else { + f.write_str(",\n")?; + } f.write_fmt(format_args!(r#" "{}": "#, key.escape_debug()))?; std::fmt::Display::fmt(&value, f)?; }