Skip to content

Make log trimming failures nonfatal and bounded - #213

Merged
AvdLee merged 1 commit into
mainfrom
fix/logs-writer-trim-crash
Aug 14, 2026
Merged

Make log trimming failures nonfatal and bounded#213
AvdLee merged 1 commit into
mainfrom
fix/logs-writer-trim-crash

Conversation

@AvdLee

@AvdLee AvdLee commented Aug 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fixes the debug-build crash Fatal error: Could not write trimmed log to target file location: .../diagnostics_log.txt by removing the assertionFailure paths in LogsWriter — trimming failures are now nonfatal.
  • Surfaces the previously swallowed atomic-write error via os_log with the full NSError (with a dedicated message for NSFileWriteOutOfSpaceError, the most plausible field cause since the atomic replace needs temp space for the full trimmed file). print is intentionally avoided because stdout/stderr are piped back into the diagnostics logger.
  • Closes the append FileHandle before trimming reads and atomically replaces the same file.
  • Trims oversized logs fully below the configured limit in one pass instead of removing only ten records per write, which previously left the file over the limit and retried the atomic replacement on every subsequent write.

Test plan

  • New regression tests: large overflow trimmed below the limit, repeated threshold crossings stay bounded, a single record larger than the limit doesn't trap, and a forced atomic-write failure (read-only parent directory) neither terminates nor loses the appended record.
  • New logger-level test exercising trimming through the serial queue at the production 2 MB limit with concurrent readLog() calls.
  • Full package test suite passes (56 tests, 0 failures).

Trimming failures previously hit an assertionFailure that terminated
debug builds while discarding the underlying filesystem error. Close
the append handle before trimming, surface trim/write errors via os_log
(including out-of-storage detection), and trim oversized logs fully
below the configured limit instead of ten records at a time.
@AvdLee
AvdLee merged commit 2200a1e into main Aug 14, 2026
1 check passed
@AvdLee
AvdLee deleted the fix/logs-writer-trim-crash branch August 14, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant