fix(forge): handle BrokenPipe in non-TTY reporter & shell writes#14215
Closed
o-az wants to merge 1 commit into
Closed
fix(forge): handle BrokenPipe in non-TTY reporter & shell writes#14215o-az wants to merge 1 commit into
o-az wants to merge 1 commit into
Conversation
51c08af to
aa146eb
Compare
zerosnacks
added a commit
to foundry-rs/compilers
that referenced
this pull request
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 ```bash 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](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 --------- Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
Contributor
|
Hey @o-az, thanks for the PR! Fixed directly in foundry-rs/compilers#367, supersedes this PR I believe; your PR has some additional handling w/ Will soon create a release for |
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.
Piping forge 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 like Solc compilation, causing println!() in
BasicStdoutReporter to abort.
Replace BasicStdoutReporter with SafeStdoutReporter that treats
BrokenPipe as non-fatal in all reporter callbacks. Also handle
BrokenPipe in the shared shell stdout/stderr write paths.
Repro:
Before: exit 134 (SIGABRT/panic)
After: exit 0, command completes normally