Open RalphDNB opened 10 months ago
The complexity with this is the assert is independent of the derive API. It would need to be worded to fit with both APIs.
Just dropping a note in here for anyone else who runs into this:
The issue is that this error is about the definition of the struct in the source code, not the arguments the user did or didn't provide when running the program. Normally, this issue would be a compiler error, not a runtime panic, and the panic message doesn't hint at that at all.
Based on epage's reply, and the panic message itself coming from clap-builder
, it seems some non-trivial work would need to be done to detect this at compile time instead of runtime, and doing so would decouple the APIs in an undesirable way.
Normally, this issue would be a compiler error, not a runtime panic, and the panic message doesn't hint at that at all.
While compile time failures would be preferred, I think asserts should be communicating that its a development problems rather than a user problem.
Note that we do encourage explicitly running debug_asserts
which would also show that these are independent of the command-line.
That's helpful to know. I'm sure I'm not alone in being caught off-guard by that approach, as I've never run into it before.
I also just ran into this and, for some reason, it was not clear to me that the error was on my side. The error message is fairly clear, but maybe it could be easier to understand if it included a link to this issue or some other page that explains how to resolve it?
Please complete the following tasks
Rust Version
1.74.1
Clap Version
4.4.11
Minimal reproducible code
Steps to reproduce the bug with the above code
cargo run
Actual Behaviour
thread 'main' panicked at /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/clap_builder-4.4.11/src/builder/debug_asserts.rs:658:17: Found non-required positional argument with a lower index than a required positional argument: "file" index Some(1) note: run with
RUST_BACKTRACE=1
environment variable to display a backtraceExpected Behaviour
A better clearer error message. Maybe something like:
Additional Context
This error message is very difficult to understand. And it is hard to know what exactly goes wrong and how to fix it.
Error message in clap code: https://github.com/clap-rs/clap/blob/d092896d61fd73a5467db85eac035a9ce2ddbc60/clap_builder/src/builder/debug_asserts.rs#L660-L661
And similar: https://github.com/clap-rs/clap/blob/d092896d61fd73a5467db85eac035a9ce2ddbc60/clap_builder/src/builder/debug_asserts.rs#L630-L632
Debug Output