clap icon indicating copy to clipboard operation
clap copied to clipboard

clap_complete: `generate()` shouldn't panic if writing fails

Open yedayak opened this issue 4 months ago • 0 comments

Please complete the following tasks

  • [x] I have searched the discussions

  • [x] I have searched the existing issues

Rust Version

rustc 1.77.2 (25ef9e3d8 2024-04-09)

Clap Version

master

Actual Behaviour

Running generate() can panic, for example if writing to a pipe ans the next program stops, or anything really stops the generation from completing. For example

cmd --generate | head

with a long enough completion will panic.

Expected Behaviour

generate() should return a Result indicating if it fails. This will be a breaking change.

Additional Context

Maybe we ignore some errors? I'm not sure what consumers will want to do with the error, and some of them might be not important enough to propagate, for example a broken pipe. The panic happens here: https://github.com/clap-rs/clap/blob/0cd10d19f0ac39341f89130d924e87879b58867f/clap_complete/src/macros.rs#L5

Opened after suggestion in #5453.

yedayak avatar Apr 15 '24 19:04 yedayak