-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Positional arg after repeated positional arg - prefer compiler error to runtime error #3281
Comments
#2720 is about supporting all debug asserts in the derive macro. As noted in that issue, there are complications with that. This falls into some of those complications because of As noted in #2720, our CHANGELOG and Derive Tutorial's tips, we encourage having a test like below so these will be caught while testing (and for all subcommands, when relevant) as compared to manual testing / using the application. #[derive(Parser)]
#[clap(author, version, about, long_about = None)]
struct Cli {
...
}
#[test]
fn verify_app() {
use clap::IntoApp;
Cli::into_app().debug_assert()
} So like #2720, I lean towards closing this issue out as "won't fix". If there are thoughts or concerns about this, let us know! |
Sounds good. May still be nice to have a better runtime error message!
was somewhat misleading to us. To my user, it seemed like it was user-error for providing the args in the wrong order (or something like that) - when actually it was a bug in the specification of the CLI by me. |
I also don't think Here's a //# clap = {version="3", features=["derive"]}
use clap::{IntoApp, Parser};
#[derive(clap::Parser, Debug)]
struct Args {
arg2: Vec<String>,
arg1: String,
}
fn main() {
Args::into_app().debug_assert();
let args = Args::parse();
dbg!(args);
} If I run it, the debug_assert doesn't catch the issue, but Args::parse() fails at runtime. |
Interesting! This lives in a completely different place but doesn't need to. My guess is it predates some of how we do assertions today. |
This will help prevent issues from being deployed to users like in clap-rs#3281 I do not consider this a breaking change because any normal operation will assert anyways.
Please complete the following tasks
Clap Version
3.0.6
Describe your use case
This code is bad. Currently when running it, it fails at runtime
Describe the solution you'd like
If possible, some kind of compile time error.
Probably would involve a proc-macro to iterate/logic over the struct and bail
Alternatives, if applicable
Status quo runtime error could work, but means you don't catch clear bugs until much later.
If we stick with status quo, a better error message might be nice.
"Found positional argument after a repeated positional argument"
Additional Context
No response
The text was updated successfully, but these errors were encountered: