Fix __send_analytics to delete event file on deserialization failure

The file was only deleted after successful deserialization + send.
Wrap the read/deserialize/send in an async block so remove_file
runs regardless of where the error occurs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bryan Helmkamp 2026-03-10 20:50:44 -04:00
parent 2735e1fc9b
commit 490dc2e5eb

View file

@ -485,9 +485,12 @@ async fn main_inner() -> Result<()> {
}
},
Command::SendAnalytics { path } => {
let json = std::fs::read(&path)?;
let track: arc_util::telemetry::event::Track = serde_json::from_slice(&json)?;
let result = arc_util::telemetry::sender::send_to_segment(&track).await;
let result = async {
let json = std::fs::read(&path)?;
let track: arc_util::telemetry::event::Track = serde_json::from_slice(&json)?;
arc_util::telemetry::sender::send_to_segment(&track).await
}
.await;
let _ = std::fs::remove_file(&path);
result?;
}