パイプ先が早期に閉じても broken pipe でパニックしない#88
Merged
Merged
Conversation
print!/println! は書き込み失敗時にパニックするため、head やページャ経由 でパイプ先が早期に閉じると素通しの panic メッセージが出てしまう。まずは 書き込み経路を一箇所に集約するところから始める。
risundle main.cpp | head のようにパイプ先が全量読まずに閉じると、print! の書き込み失敗がそのままパニックしていた (#62)。出力量が最も大きく実害の 大半を占めるこの経路から、新設した output::write に切り替える。
一覧・詳細表示も risundle library list | head のようなパイプ運用があり 得るため、bundle と同じく println! を broken-pipe 安全な経路に揃える。
main.cpp 自身をコメントで肥大化させ、ライブラリやコンパイラ固有の機能に 頼らず出力サイズを稼いだ上でパイプを早期に閉じ、stderr に panicked が 出ないことを確認する。修正前のコードに対しては実際に失敗することを 手元で確認済み。
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThe 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. ChangesCLI output handling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
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.
Fixes #62
変更内容
src/output.rsを新設し、stdout への書き込みを一箇所に集約。ErrorKind::BrokenPipeは静かに正常終了 (exit(0)) し、それ以外の書き込み失敗のみ従来通りパニックする。bundle.rsのprint!(出力量が最も大きく実害の中心) をこの経路に差し替え。library.rsのprintln!(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
Tests