fix(bazel): surface swallowed Close and logger-init errors#130
Merged
Conversation
|
|
The bazelisk download swallowed several errors around the temp-file install: - The success-path tmp.Close() was ignored, so a failed flush (disk full, network FS) could leave a truncated binary that was then chmod'd and renamed into place — defeating the temp-file-then-rename guard. Its error is now checked and propagated. - The io.Copy error path discarded tmp.Close(); it is now folded into the returned error via errors.Join. - The deferred os.Remove(tmpPath) ignored its error and ran even on success (where the file was already renamed away, guaranteeing ENOENT). Cleanup now runs only on failure and joins any removal error into the result. Also handle the discarded zap.NewDevelopment() error in the example server and client, which would nil-panic at defer zl.Sync() on the (rare) init failure. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ecce560 to
64cae9c
Compare
yushan8
approved these changes
Jun 30, 2026
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.
Summary
Fixes several swallowed-error issues found while auditing the codebase for dropped errors.
core/bazel/bazel.go— bazelisk download install pathThe temp-file-then-rename dance exists specifically to avoid installing partial binaries, but three ignored errors undermined it:
tmp.Close()was ignored. A failed flush (disk full, network filesystem) could leave a truncated file that was thenchmod'd andrename'd into place. Its error is now checked and propagated.io.Copyerror path discardedtmp.Close(). It is now folded into the returned error viaerrors.Join.defer os.Remove(tmpPath)ignored its error and ran on every path — including success, where the file had already been renamed away, guaranteeing an ENOENT. Cleanup now runs only on failure (via a named-return defer) and joins any removal error into the result.example/main.goandexample/client/client.goDiscarded
zap.NewDevelopment()error:zl, _ := zap.NewDevelopment()followed bydefer zl.Sync()would nil-panic on the (rare) init failure. The server returns the wrapped error fromrun(); the client prints to stderr and exits, matching its existingmain()style.Testing
make build— passesmake test— all 14 test targets passmake gazelle— no BUILD changes🤖 Generated with Claude Code