diff --git a/nexus/src/app/background/tasks/support_bundle_collector.rs b/nexus/src/app/background/tasks/support_bundle_collector.rs index 2190a836a34..5eec11e35e6 100644 --- a/nexus/src/app/background/tasks/support_bundle_collector.rs +++ b/nexus/src/app/background/tasks/support_bundle_collector.rs @@ -5,6 +5,7 @@ //! Background task for managing Support Bundles use crate::app::background::BackgroundTask; +use anyhow::Context; use camino::Utf8DirEntry; use camino::Utf8Path; use camino_tempfile::Utf8TempDir; @@ -772,7 +773,7 @@ async fn sha2_hash(file: &mut tokio::fs::File) -> anyhow::Result { } /// Run a `sled-dianostics` future and save its output to a corresponding file. -async fn save_diag_cmd_output_or_error( +async fn save_diag_cmd_output_or_error( path: &Utf8Path, command: &str, future: F, @@ -780,7 +781,7 @@ async fn save_diag_cmd_output_or_error( where F: Future< Output = Result< - sled_agent_client::ResponseValue, + sled_agent_client::ResponseValue, sled_agent_client::Error, >, > + Send, @@ -789,11 +790,14 @@ where match result { Ok(result) => { let output = result.into_inner(); - tokio::fs::write( - path.join(format!("{command}.txt")), - format!("{output:?}"), - ) - .await?; + let json = serde_json::to_string(&output).with_context(|| { + format!("failed to serialize {command} output as json") + })?; + tokio::fs::write(path.join(format!("{command}.json")), json) + .await + .with_context(|| { + format!("failed to write output of {command} to file") + })?; } Err(err) => { tokio::fs::write(