Skip to content
This repository was archived by the owner on Apr 20, 2026. It is now read-only.

fix(report): handle BrokenPipe in BasicStdoutReporter#367

Merged
zerosnacks merged 2 commits into
mainfrom
zerosnacks/fix-broken-pipe-reporter
Apr 9, 2026
Merged

fix(report): handle BrokenPipe in BasicStdoutReporter#367
zerosnacks merged 2 commits into
mainfrom
zerosnacks/fix-broken-pipe-reporter

Conversation

@decofe
Copy link
Copy Markdown
Contributor

@decofe decofe commented Apr 9, 2026

Piping compiler output to tee crashes with a BrokenPipe panic. Some widely-deployed tee implementations (uutils-coreutils ≤ 0.8, default on NixOS and common via Homebrew) close the read end of the pipe during write pauses (e.g. during Solc compilation), causing println!() in BasicStdoutReporter to abort.

Replace println!/eprintln! with a write_line helper that treats BrokenPipe as non-fatal. Non-BrokenPipe errors still panic, preserving the prior behavior.

Repro

tmpdir="$(mktemp -d)"
cd "$tmpdir"
forge init --quiet
forge build | tee out.log

Before: exit 134 (SIGABRT/panic)
After: exit 0

Changes

  • Replace println!/eprintln! in BasicStdoutReporter with write_line() helper
  • write_line() silently discards BrokenPipe, panics on other I/O errors
  • Add tests for BrokenPipe, non-BrokenPipe, and newline-terminated output

Context

This is the upstream fix for foundry-rs/foundry#14215, which works around this issue by duplicating BasicStdoutReporter as SafeStdoutReporter in foundry. Fixing it here eliminates the need for a downstream copy.

Prompted by: zerosnacks

Replace println!/eprintln! in BasicStdoutReporter with a write_line
helper that treats BrokenPipe as non-fatal. This prevents panics when
piping compiler output through consumers that may close the pipe early
(e.g. tee, head). Non-BrokenPipe errors still panic, preserving the
prior behavior.

Repro (with uutils-coreutils tee ≤ 0.8):

    forge build | tee out.log

Before: exit 134 (SIGABRT/panic)
After: exit 0

Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
@zerosnacks zerosnacks merged commit 664197b into main Apr 9, 2026
18 checks passed
@zerosnacks zerosnacks deleted the zerosnacks/fix-broken-pipe-reporter branch April 9, 2026 14:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants