Skip to content
This repository was archived by the owner on Jun 29, 2026. It is now read-only.

Commit de9b1b1

Browse files
committed
fix: Replace unwrap() calls with error logging in collection loop
JSON serialization and file write can fail at runtime (e.g. disk full). Log the error and continue the loop instead of crashing, since this tool may run continuously for hours.
1 parent 5dc8454 commit de9b1b1

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

‎src/main.rs‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,24 @@ async fn main() {
7272

7373
let system_information = SystemInformation::collect(&mut collect_ctx).await;
7474

75-
let serialized = serde_json::to_string_pretty(&system_information).unwrap();
76-
if let Some(output_path) = &opts.output {
77-
std::fs::write(output_path, &serialized).unwrap();
75+
match serde_json::to_string_pretty(&system_information) {
76+
Ok(serialized) => {
77+
if let Some(output_path) = &opts.output
78+
&& let Err(err) = std::fs::write(output_path, &serialized)
79+
{
80+
tracing::error!(
81+
path = %output_path.display(),
82+
error = &err as &dyn std::error::Error,
83+
"failed to write JSON output file"
84+
);
85+
}
86+
}
87+
Err(err) => {
88+
tracing::error!(
89+
error = &err as &dyn std::error::Error,
90+
"failed to serialize system information"
91+
);
92+
}
7893
}
7994

8095
match opts.loop_interval {

0 commit comments

Comments
 (0)