Inner fallible implementation of [`append_agent_trace`].
(record: &TraceRecord, root: &Path)
| 448 | |
| 449 | /// Inner fallible implementation of [`append_agent_trace`]. |
| 450 | fn try_append_agent_trace(record: &TraceRecord, root: &Path) -> std::io::Result<()> { |
| 451 | use std::fs::{self, OpenOptions}; |
| 452 | use std::io::Write; |
| 453 | |
| 454 | let dir = root.join(".agent-trace"); |
| 455 | fs::create_dir_all(&dir)?; |
| 456 | |
| 457 | let path = dir.join("traces.jsonl"); |
| 458 | let mut file = OpenOptions::new().create(true).append(true).open(&path)?; |
| 459 | |
| 460 | let line = serde_json::to_string(record) |
| 461 | .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e.to_string()))?; |
| 462 | writeln!(file, "{}", line)?; |
| 463 | |
| 464 | log::debug!( |
| 465 | "agent-trace: appended record {} to {}", |
| 466 | record.id, |
| 467 | path.display() |
| 468 | ); |
| 469 | |
| 470 | Ok(()) |
| 471 | } |
| 472 | |
| 473 | // --------------------------------------------------------------------------- |
| 474 | // Tests |
no test coverage detected