File tree 1 file changed +11
-7
lines changed
nexus/src/app/background/tasks 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 5
5
//! Background task for managing Support Bundles
6
6
7
7
use crate :: app:: background:: BackgroundTask ;
8
+ use anyhow:: Context ;
8
9
use camino:: Utf8DirEntry ;
9
10
use camino:: Utf8Path ;
10
11
use camino_tempfile:: Utf8TempDir ;
@@ -772,15 +773,15 @@ async fn sha2_hash(file: &mut tokio::fs::File) -> anyhow::Result<ArtifactHash> {
772
773
}
773
774
774
775
/// Run a `sled-dianostics` future and save its output to a corresponding file.
775
- async fn save_diag_cmd_output_or_error < F , D : std :: fmt :: Debug > (
776
+ async fn save_diag_cmd_output_or_error < F , S : serde :: Serialize > (
776
777
path : & Utf8Path ,
777
778
command : & str ,
778
779
future : F ,
779
780
) -> anyhow:: Result < ( ) >
780
781
where
781
782
F : Future <
782
783
Output = Result <
783
- sled_agent_client:: ResponseValue < D > ,
784
+ sled_agent_client:: ResponseValue < S > ,
784
785
sled_agent_client:: Error < sled_agent_client:: types:: Error > ,
785
786
> ,
786
787
> + Send ,
@@ -789,11 +790,14 @@ where
789
790
match result {
790
791
Ok ( result) => {
791
792
let output = result. into_inner ( ) ;
792
- tokio:: fs:: write (
793
- path. join ( format ! ( "{command}.txt" ) ) ,
794
- format ! ( "{output:?}" ) ,
795
- )
796
- . await ?;
793
+ let json = serde_json:: to_string ( & output) . with_context ( || {
794
+ format ! ( "failed to serialize {command} output as json" )
795
+ } ) ?;
796
+ tokio:: fs:: write ( path. join ( format ! ( "{command}.json" ) ) , json)
797
+ . await
798
+ . with_context ( || {
799
+ format ! ( "failed to write output of {command} to file" )
800
+ } ) ?;
797
801
}
798
802
Err ( err) => {
799
803
tokio:: fs:: write (
You can’t perform that action at this time.
0 commit comments