Skip to content
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

Unhelpfully-aimed error-messages on subcommands #187

Open
LunarTulip opened this issue Feb 2, 2024 · 0 comments
Open

Unhelpfully-aimed error-messages on subcommands #187

LunarTulip opened this issue Feb 2, 2024 · 0 comments

Comments

@LunarTulip
Copy link

Consider this example/test source code:

use argh::FromArgs;

#[derive(FromArgs)]
/// Example
struct Args {
    #[argh(subcommand)]
    subcommand: Subcommand,
}

#[derive(FromArgs)]
#[argh(subcommand)]
enum Subcommand {
    One(SubcommandOption1),
}

#[derive(FromArgs)]
#[argh(subcommand, name = "one")]
/// First subcommand
struct SubcommandOption1 {
    #[argh(positional)]
    /// small number
    one: u8,
}

fn main() {
    let _args: Args = argh::from_env();
}

Running cargo run -- one 257 (or building and then running ./test.exe one 257) on this will predictably fail, because the number 257 doesn't fit inside a u8. But let's look at the error message that gets returned on that failure:

Error parsing positional argument 'one' with value '257': number too large to fit in target type

Run test.exe --help for more information.

But note the jump! That's not the help page for the subcommand that contains the positional argument 'one'; that's the root help page for the overall command. Users are being directed to the wrong place! They'll need to manually navigate their way to finding the subcommand's help menu from there. Users less familiar with how argh organizes its help menus might not even realize that there is a subcommand help menu they should be accessing instead.

I suggest, as an alternative, that, when a subcommand returns an error of this sort, the error message's direction-to-the-help-menu should point directly at the subcommand which threw the error. So, for instance, in this case, Run test.exe one --help for more information..

(All example code here was compiled and run on Windows 10, using argh 0.1.12.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant