Skip to content

fix: propagate file close and gzip flush errors - #13

Merged
gacevicljubisa merged 1 commit into
mainfrom
fix/savelogs-close-error
Aug 28, 2026
Merged

fix: propagate file close and gzip flush errors#13
gacevicljubisa merged 1 commit into
mainfrom
fix/savelogs-close-error

Conversation

@gacevicljubisa

Copy link
Copy Markdown
Member

Summary

SaveLogsAsync and CompressFile swallowed Close errors via bare defers:

  • filestore.SaveLogsAsync: OS-buffered writes can surface a failure only when the file is flushed at close time (disk full, quota, network fs), so a failed close reported an incomplete export as success.
  • gzipstore.CompressFile: worse — gzip.Writer.Close flushes the remaining compressed bytes and writes the gzip footer, so a swallowed error there reported a truncated/corrupt .gzip archive as success.

Close errors are now joined into the returned error via errors.Join. Context cancellation is preserved: errors.Is(err, context.Canceled) in cmd/export.go still holds when both cancellation and a close failure occur.

Flagged in the adversarial review of #8 (Finding 2); the bug predates that PR, hence a separate fix from main.

Changes

  • Extract saveLogs/compress helpers taking injectable writers so the close-error path is testable.
  • Join close/flush errors into the returned error.
  • Add tests: close-error propagation, cancellation + close-failure joining, NDJSON happy path, gzip round trip (the two packages previously had no tests).

Testing

  • go test -race ./... — all pass
  • make lint — 0 issues

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q7Linc1WFpVVE4mEj6xmjG

SaveLogsAsync and CompressFile swallowed Close errors via bare defers, so
a failed flush at close time (disk full, quota, network fs) reported an
incomplete export or a truncated gzip archive as success. Close errors
are now joined into the returned error; context cancellation is
preserved through errors.Join so errors.Is(err, context.Canceled) in
cmd/export.go still holds.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q7Linc1WFpVVE4mEj6xmjG
@gacevicljubisa
gacevicljubisa merged commit c7b7230 into main Aug 28, 2026
3 checks passed
@gacevicljubisa
gacevicljubisa deleted the fix/savelogs-close-error branch August 28, 2026 14:35
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.

2 participants