Skip to content

[BUG] --quiet, --offline and --teach-me hide the real CLI parse error #728

Description

@KhomDev

Description

When a command line contains one of the top-level options (--quiet, --offline, --teach-me) and the rest of the command fails to parse, the CLI reports

error: unexpected argument '--quiet' found

instead of the real error. Without the option, the correct error is printed. It happens for invalid values and for unknown commands alike, and the option may come before or after the failing argument.

Reproduce

near-cli-rs 0.31.1; no network access or keys are needed.

$ near --quiet transaction print-transaction signed "###"
error: unexpected argument '--quiet' found

Exit code 2. The same command without the option:

$ near transaction print-transaction signed "###"
error: invalid value '###' for '[SIGNED_TRANSACTION]': base64 transaction sequence is invalid: Invalid byte 35, offset 0.

Unknown commands are affected the same way:

$ near --quiet bogus-command
error: unexpected argument '--quiet' found

Without the option, the same command reports that the command or its extension binary does not exist (exit code 1). --offline and --teach-me behave identically, and the option does not have to precede the failing argument: near transaction print-transaction signed "###" --quiet also prints the flag error.

Expected

The real error: the invalid value, or the unknown command. A top-level option should not change which error is shown.

Actual

The legacy-JS parser's unknown-argument error is shown instead, and the real error is lost.

Cause

src/main.rs:113-132. When Cmd::try_parse() fails with anything other than help or version, the CLI falls back to the legacy JS command parser for backward compatibility. If that parser fails with anything other than InvalidSubcommand, its error is printed and the Rust error is discarded:

Err(js_cmd_error) => {
    // js and rust both don't understand the subcommand
    if cmd_error.kind() == clap::error::ErrorKind::InvalidSubcommand
        && js_cmd_error.kind() == clap::error::ErrorKind::InvalidSubcommand
    {
        return crate::common::try_external_subcommand_execution(cmd_error);
    }

    // js understand the subcommand
    if js_cmd_error.kind() != clap::error::ErrorKind::InvalidSubcommand {
        js_cmd_error.exit();
    }

    cmd_error.exit();
}

The comment "js understand the subcommand" does not hold for the three global options: the JS parser does not define them, so it fails with an unknown-argument error even when it did not understand the command.

Suggested fix

Only use the JS parser's error when the Rust error is InvalidSubcommand (the command name is unknown, so the legacy CLI may know it); for every other Rust error, print cmd_error:

if cmd_error.kind() == clap::error::ErrorKind::InvalidSubcommand
    && js_cmd_error.kind() != clap::error::ErrorKind::InvalidSubcommand
{
    js_cmd_error.exit();
}
cmd_error.exit();

Version

Reproduced with near-cli-rs 0.31.1 (latest release). src/main.rs is identical on main (cfbc0a6). The legacy fallback was introduced in #366; this block was last changed in #560 (2026-04-16), and no change to it is in flight.

🤖 Generated with Claude Code

Activity

  1. added theissue type on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions