MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / read_errors

Function read_errors

atomic-agent/src/hook_health.rs:385–416  ·  view source on GitHub ↗

Read a bounded tail of `hook-errors.log` and aggregate it. Returns `None` when the file is absent. A file that exists but cannot be read or parsed yields an empty report rather than an error, because the point of the report is to explain the situation.

(repo_root: &Path)

Source from the content-addressed store, hash-verified

383/// read or parsed yields an empty report rather than an error, because the
384/// point of the report is to explain the situation.
385pub fn read_errors(repo_root: &Path) -> Option<HookErrors> {
386 let path = repo_root.join(".atomic").join("hook-errors.log");
387 let meta = std::fs::metadata(&path).ok()?;
388 let file_len = meta.len();
389 let mut file = std::fs::File::open(&path).ok()?;
390
391 // Read only the tail; the file is unbounded and never rotated.
392 let start = file_len.saturating_sub(ERROR_LOG_TAIL_BYTES);
393 if start > 0 {
394 file.seek(SeekFrom::Start(start)).ok()?;
395 }
396 let mut buf = Vec::new();
397 std::io::Read::read_to_end(&mut file, &mut buf).ok()?;
398
399 let text = String::from_utf8_lossy(&buf);
400 // A tail seek can land mid-line, in which case the first line read is a
401 // fragment and must be dropped. When the whole file was read (start ==
402 // 0) nothing is partial, so the first line is real and must be kept —
403 // dropping it would silently lose the oldest entry on every small log.
404 let body = if start > 0 {
405 match text.find('\n') {
406 Some(i) => &text[i + 1..],
407 None => "",
408 }
409 } else {
410 &text
411 };
412
413 let (entries, lines) = parse_error_log(body);
414
415 Some(aggregate(&entries, lines, start))
416}
417
418/// Parse a log into entries, folding continuation lines into their entry.
419///

Callers 3

to_jsonMethod · 0.85
print_hook_healthFunction · 0.85

Calls 5

openFunction · 0.85
parse_error_logFunction · 0.85
aggregateFunction · 0.85
okMethod · 0.45
lenMethod · 0.45

Tested by 1