Skip to content

Logs → fix messages containing new lines corrupting format - #121

Merged
revett merged 5 commits into
8thpark:mainfrom
kwame-Owusu:fix/log-format
Jul 23, 2026
Merged

revett merged 5 commits into
8thpark:mainfrom
kwame-Owusu:fix/log-format

Conversation

@kwame-Owusu

@kwame-Owusu kwame-Owusu commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

resolves #97

Problem

Persisted log lines are newline delimited and messages are written verbatim. An error message containing a newline (common in thrown I/O and provider errors) splits into one valid line plus malformed continuation lines that the parser silently drops, so the most interesting half of an error never appears in the log view.

formatLogLine wrote messages verbatim; any \n in the message broke the line delimiter and parseLogLine silently dropped the continuation lines.

Changes

Added escapeMessage / unescapeMessage at the serialization boundary. formatLogLine escapes , \n, \r before writing; parseLogLine unescapes them after reading. Unescape uses character-by-character scanning to avoid matching \n inside the stored \ sequence.

Tests

Eight new cases, round-trips for embedded newline, CR, literal backslash-n, both together, multiple newlines, CRLF; a single-line guarantee check; and an adapter split-and-parse simulation.

Greptile Summary

This PR fixes log corruption caused by error messages containing newlines being written verbatim into a newline-delimited log file, causing the parser to silently drop the continuation lines. It also upgrades the 404 check in readRemoteManifest from message-text sniffing to the proper status field.

  • Adds escapeMessage (escape \ → \\, \n → \n, \r → \r) and unescapeMessage (character-by-character scanner) at the formatLogLine/parseLogLine boundary in log.ts. The escape ordering (backslash first) correctly prevents literal \n sequences from being misread, and the scanner correctly handles \\n without consuming the n as an escape target.
  • Replaces the fetched.message.includes("(404)") sniff in sync.ts with fetched.status === "not_found", closing the TODO added in Results conflate 404 with other errors #41 now that ResultStatus carries a proper discriminant.

Confidence Score: 5/5

Safe to merge — the escape/unescape logic is correct in all tested and edge cases, and the sync status check is a straightforward improvement.

The escape ordering (backslash before newline) and the character-by-character unescape scanner are both implemented correctly and verified across eight round-trip cases including the tricky
ambiguity. The sync.ts change removes a fragile string-sniff in favour of the typed status discriminant that already existed on GetResult.

No files require special attention.

Important Files Changed

Filename Overview
src/log/log.ts Adds escapeMessage/unescapeMessage at the format/parse boundary; escape ordering (backslash first, then newline, then CR) and char-by-char unescape are both correct; no issues found.
src/log/log.test.ts Eight new test cases covering all escape combinations (embedded newline, CR, literal backslash-n, CRLF, multiple newlines, both together), a single-line guarantee, and an adapter split-and-parse simulation; coverage is thorough.
src/sync/sync.ts Replaces fragile message.includes("(404)") sniffing with status === "not_found" (closing the TODO referencing #41), and reformats two multi-field union arms for line-length compliance; both changes are correct.

Reviews (3): Last reviewed commit: "Merge branch 'main' into fix/log-format" | Re-trigger Greptile

@kwame-Owusu kwame-Owusu changed the title Logs -> fix messages containing new lines corrupting format Logs → fix messages containing new lines corrupting format Jul 23, 2026
@revett
revett merged commit 2d293c6 into 8thpark:main Jul 23, 2026
10 checks passed
@kwame-Owusu
kwame-Owusu deleted the fix/log-format branch July 27, 2026 12:46
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.

Messages containing newlines corrupt the log format

2 participants