Skip to content

fix(bazel): surface swallowed Close and logger-init errors#130

Merged
sbalabanov merged 1 commit into
mainfrom
fix-swallowed-close-and-logger-errors
Jun 30, 2026
Merged

fix(bazel): surface swallowed Close and logger-init errors#130
sbalabanov merged 1 commit into
mainfrom
fix-swallowed-close-and-logger-errors

Conversation

@sbalabanov

@sbalabanov sbalabanov commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes several swallowed-error issues found while auditing the codebase for dropped errors.

core/bazel/bazel.go — bazelisk download install path

The temp-file-then-rename dance exists specifically to avoid installing partial binaries, but three ignored errors undermined it:

  1. Success-path tmp.Close() was ignored. A failed flush (disk full, network filesystem) could leave a truncated file that was then chmod'd and rename'd into place. Its error is now checked and propagated.
  2. io.Copy error path discarded tmp.Close(). It is now folded into the returned error via errors.Join.
  3. 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.go and example/client/client.go

Discarded zap.NewDevelopment() error: zl, _ := zap.NewDevelopment() followed by defer zl.Sync() would nil-panic on the (rare) init failure. The server returns the wrapped error from run(); the client prints to stderr and exits, matching its existing main() style.

Testing

  • make build — passes
  • make test — all 14 test targets pass
  • make gazelle — no BUILD changes

🤖 Generated with Claude Code

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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>
@sbalabanov sbalabanov force-pushed the fix-swallowed-close-and-logger-errors branch from ecce560 to 64cae9c Compare June 30, 2026 20:34
@sbalabanov sbalabanov marked this pull request as ready for review June 30, 2026 20:34
@sbalabanov sbalabanov requested review from a team as code owners June 30, 2026 20:34
@sbalabanov sbalabanov merged commit 83c44e5 into main Jun 30, 2026
12 of 13 checks passed
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.

4 participants