Skip to content

パイプ先が早期に閉じても broken pipe でパニックしない#88

Merged
TwoSquirrels merged 5 commits into
mainfrom
fix/broken-pipe-panic
Jul 13, 2026
Merged

パイプ先が早期に閉じても broken pipe でパニックしない#88
TwoSquirrels merged 5 commits into
mainfrom
fix/broken-pipe-panic

Conversation

@TwoSquirrels

@TwoSquirrels TwoSquirrels commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Fixes #62

変更内容

  • src/output.rs を新設し、stdout への書き込みを一箇所に集約。ErrorKind::BrokenPipe は静かに正常終了 (exit(0)) し、それ以外の書き込み失敗のみ従来通りパニックする。
  • bundle.rsprint! (出力量が最も大きく実害の中心) をこの経路に差し替え。
  • library.rsprintln! (list/show 等) も同様に差し替え、| head 等のパイプ運用への耐性を揃えた。

テスト

  • broken_pipe_while_writing_output_does_not_panic を追加。main.cpp 自身をコメントで肥大化させて出力サイズを稼ぎ (ライブラリやコンパイラ固有の機能に頼らない)、パイプを早期に閉じても stderr に panicked が出ないことを確認する。
  • 修正前のコードに対して実際にこのテストが失敗する (パニックを再現する) ことを手元で確認済み。
  • cargo fmt --check / cargo clippy --all-targets --all-features -- -D warnings / cargo test --all-features すべて通過。

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved command output handling when output is redirected or consumed by another process.
    • Prevented broken-pipe scenarios from producing panic messages or unnecessary failures.
    • Standardized output behavior across bundling and library management commands.
  • Tests

    • Added coverage for bundling when the output stream closes unexpectedly.

print!/println! は書き込み失敗時にパニックするため、head やページャ経由
でパイプ先が早期に閉じると素通しの panic メッセージが出てしまう。まずは
書き込み経路を一箇所に集約するところから始める。
risundle main.cpp | head のようにパイプ先が全量読まずに閉じると、print!
の書き込み失敗がそのままパニックしていた (#62)。出力量が最も大きく実害の
大半を占めるこの経路から、新設した output::write に切り替える。
一覧・詳細表示も risundle library list | head のようなパイプ運用があり
得るため、bundle と同じく println! を broken-pipe 安全な経路に揃える。
main.cpp 自身をコメントで肥大化させ、ライブラリやコンパイラ固有の機能に
頼らず出力サイズを稼いだ上でパイプを早期に閉じ、stderr に panicked が
出ないことを確認する。修正前のコードに対しては実際に失敗することを
手元で確認済み。
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1bac9334-02c3-41ca-b639-71b4454b7ba4

📥 Commits

Reviewing files that changed from the base of the PR and between efe9415 and a863eaf.

📒 Files selected for processing (5)
  • src/commands/bundle.rs
  • src/commands/library.rs
  • src/main.rs
  • src/output.rs
  • tests/cli.rs

📝 Walkthrough

Walkthrough

The CLI introduces centralized stdout helpers that handle broken pipes cleanly. Bundle and library commands now use these helpers, with an end-to-end test covering early stdout closure.

Changes

CLI output handling

Layer / File(s) Summary
Central stdout writer
src/main.rs, src/output.rs
Adds shared write and write_line helpers; broken-pipe errors exit successfully while other write errors panic.
Command output integration
src/commands/bundle.rs, src/commands/library.rs, tests/cli.rs
Routes bundle and library messages through the shared writers and adds a subprocess test for broken-pipe output.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the core fix: avoiding broken-pipe panics when the pipe closes early.
Linked Issues check ✅ Passed The PR implements silent BrokenPipe exit, reroutes CLI output through helpers, and adds a regression test for early pipe closure.
Out of Scope Changes check ✅ Passed The changes stay focused on stdout handling and the regression test, with no unrelated feature work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/broken-pipe-panic

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@TwoSquirrels TwoSquirrels marked this pull request as ready for review July 13, 2026 19:34
@TwoSquirrels TwoSquirrels merged commit a591260 into main Jul 13, 2026
10 checks passed
@TwoSquirrels TwoSquirrels deleted the fix/broken-pipe-panic branch July 13, 2026 19:44
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.

パイプ先が早期に閉じると broken pipe でパニックする

1 participant