Fix reachable panic in CLI flag handling#14299
Fix reachable panic in CLI flag handling#14299gesslerpd wants to merge 1 commit intoastral-sh:mainfrom
Conversation
|
Hm, but this should be unreachable since these use Lines 239 to 244 in 5b2c359 |
|
I guess this is a Clap bug? |
|
Yeah it could be a Clap issue, seems reasonable for UV to make them cancel out for now. Purposely used a non-destructive example to show it but think it has to do with when opposing flags exist at different subcommand levels. |
|
Yeah that makes sense. I don't think they should cancel out though, the latter one should "win". If they cancel out, we'll use the default value instead so I think this is a correctness bug if we don't panic. |
|
I'm not familiar with Clap, since these options are shared across levels I think that following should be equivalent (using harmless repro command)
Possibly the top example is not currently a cancel out scenario though, when clap is doing its normal overrides_with behavior? It's a whatever is last wins? In that case, I guess then only way to workaround this would be fixing in Clap. |
|
Closing in favor of issue/pr in https://github.com/clap-rs/clap |
|
Filed upstream: clap-rs/clap#6049 |
Clap does not perform global validation, so flag that are declared as overriding can be set at the same time: clap-rs/clap#6049. This would previously cause a panic. We work around this by choosing the yes-value always and writing a warning. An alternative would be erroring when both are set, but it's unclear to me if this may break things we want to support. (`UV_OFFLINE=1 cargo run -q pip --no-offline install tqdm --no-cache` is already banned). Fixes #14299 **Test Plan** ``` $ cargo run -q pip --offline install --no-offline tqdm --no-cache warning: Boolean flags on different levels are not correctly supported (clap-rs/clap#6049) × No solution found when resolving dependencies: ╰─▶ Because tqdm was not found in the cache and you require tqdm, we can conclude that your requirements are unsatisfiable. hint: Packages were unavailable because the network was disabled. When the network is disabled, registry packages may only be read from the cache. ```
Clap does not perform global validation, so flag that are declared as overriding can be set at the same time: clap-rs/clap#6049. This would previously cause a panic. We work around this by choosing the yes-value always and writing a warning. An alternative would be erroring when both are set, but it's unclear to me if this may break things we want to support. (`UV_OFFLINE=1 cargo run -q pip --no-offline install tqdm --no-cache` is already banned). Fixes #14299 **Test Plan** ``` $ cargo run -q pip --offline install --no-offline tqdm --no-cache warning: Boolean flags on different levels are not correctly supported (clap-rs/clap#6049) × No solution found when resolving dependencies: ╰─▶ Because tqdm was not found in the cache and you require tqdm, we can conclude that your requirements are unsatisfiable. hint: Packages were unavailable because the network was disabled. When the network is disabled, registry packages may only be read from the cache. ```
Clap does not perform global validation, so flag that are declared as overriding can be set at the same time: clap-rs/clap#6049. This would previously cause a panic. We work around this by choosing the yes-value always and writing a warning. An alternative would be erroring when both are set, but it's unclear to me if this may break things we want to support. (`UV_OFFLINE=1 cargo run -q pip --no-offline install tqdm --no-cache` is already banned). Fixes #14299 **Test Plan** ``` $ cargo run -q pip --offline install --no-offline tqdm --no-cache warning: Boolean flags on different levels are not correctly supported (clap-rs/clap#6049) × No solution found when resolving dependencies: ╰─▶ Because tqdm was not found in the cache and you require tqdm, we can conclude that your requirements are unsatisfiable. hint: Packages were unavailable because the network was disabled. When the network is disabled, registry packages may only be read from the cache. ```
Summary
Previously it was possible to reach panic condition in CLI flag handling when opposing flags were passed at different subcommand levels.
For example
uv self --offline version --no-offlinepanics with the followingRUST_BACKTRACE.Test Plan
The panic condition is removed in favor of
Noneso should be impossible to reach condition now.Based on the unreachable message, not sure if this is some issue with Clap or uv's usage of it but seems reasonable they would cancel out to
None.