Repository navigation
fix(cli): only print "CSV report written to" after a complete CSV write - #2203
Merged
Merged
Conversation
writeMultiServiceCSVReport deferred writer.Flush() and never checked writer.Error(), so a failed flush (full disk, failing mount) lost the whole report while returning nil. It also returned nil without creating a file when there were no results. Both callers printed "CSV report written to" on any nil return. Flush explicitly and return writer.Error(); return a file Close error instead of only logging it. Route both callers through a new writeCSVReport helper that says "CSV report not written" for a run with no results, and prints the success line only after a complete write. Closes LeanerCloud#2004 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Member
Independent review verdict: CLEAN, head
|
IAmJSD
marked this pull request as ready for review
October 16, 2026 10:01
This was referenced Oct 16, 2026
Merged
Member
|
@coderabbitai full review |
Contributor
✅ Action performedFull review finished. |
Member
Merge gate met at
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
writeMultiServiceCSVReport(cmd/multi_service_csv.go) had two problems:defer writer.Flush()and never readwriter.Error().csv.Writerbuffers its output, so for a normal-sized report every byte reaches the file at that flush. A failed flush (full disk, failing network mount) lost the header and rows, and the function still returned nil. A failedfile.Close()was only logged.os.Create, so no file was created.Both callers in
cmd/multi_service.go(writeReportAndSummaryandrunCSVPurchases) printedCSV report written to: <path>on any nil return. That told the operator a file existed when it was truncated, empty or missing. On a--purchaserun, this CSV is the only record of what was bought.Fix
writeMultiServiceCSV(io.Writer, results), which callswriter.Flush()explicitly and returnswriter.Error().writeMultiServiceCSVReportkeeps its signature and its empty-results behaviour (no file, nil). It now returns afile.Close()error instead of only logging it.writeCSVReport(results, path)helper is now used by both callers. With no results it printsNo purchase results; CSV report not written.On error it logs the same warning as before. It printsCSV report written to:only after a complete, flushed and closed write.Closes #2004
Verification
All commands were run in the worktree with
AWS_CONFIG_FILE=/dev/null AWS_SHARED_CREDENTIALS_FILE=/dev/null, because this machine's default AWS profile is invalid and unrelated tests fail without it.New tests in
cmd/multi_service_csv_test.go:TestWriteMultiServiceCSV_FlushErrorIsReturned: a writer that always fails must produce an error.TestWriteReportAndSummary_NoResultsDoesNotClaimCSVWritten: a run with no results creates no file, does not print "written to", and does print "not written".TestWriteCSVReport_FailureDoesNotClaimCSVWritten: guard test. A create failure prints no success line, and a successful write prints the path. This one already passed before the fix.Fail before (simulated): the old code can't compile against the new test helpers, so I built a pre-fix copy of this branch. It restores
defer writer.Flush()with nowriter.Error()check and drops the empty-results branch. On that copy:Pass after: all three new tests and the existing
TestWriteMultiServiceCSVReport*tests pass.Also run:
go test ./...: okgo vet ./...: cleangolangci-lint run ./...(v2.10.1, the CI pin): 0 issuesmake build: okCoverage gap: the flush failure is tested with a failing
io.Writer, not a real full disk or network mount. No real AWS calls or purchases were made.Notes
cmd/multi_service.go. This PR only changes that file at the two CSV-report call sites, so any conflict should be small and easy to resolve.triaged,priority/p2,severity/medium,urgency/this-quarter,impact/few,effort/xs,type/bug.🤖 Generated with Claude Code
Summary by CodeRabbit