Skip to content
Latchkey

cargo "Found argument X which wasn't expected" in CI

cargo parsed the command line and rejected an argument it does not understand. Either a flag was passed to the wrong subcommand, or a subcommand provided by a separate plugin (cargo-nextest, cargo-deny) is not installed on the runner.

What this error means

A cargo step fails with "error: Found argument X which wasn't expected, or isn't valid in this context" or "no such subcommand", with a usage hint.

cargo
error: Found argument 'nextest' which wasn't expected, or isn't valid in this context

Usage: cargo [+toolchain] [OPTIONS] [COMMAND]
For more information, try '--help'.

Common causes

A plugin subcommand is not installed

Commands like cargo nextest or cargo deny are external binaries; if the plugin is not installed, cargo treats the subcommand as an unexpected argument.

A flag passed to the wrong subcommand or version

A flag valid for one subcommand (or a newer cargo) is rejected by the subcommand or cargo version actually on the runner.

How to fix it

Install the plugin that provides the subcommand

Install the external cargo command before invoking it. Prebuilt-binary installers are faster than building from source.

.github/workflows/ci.yml
- uses: taiki-e/install-action@v2
  with:
    tool: cargo-nextest
- run: cargo nextest run

Check the flag against the right command and version

  1. Run cargo <subcommand> --help to confirm the flag exists there.
  2. Check cargo --version; a newer flag may not exist on an older toolchain.
  3. Move the flag to the subcommand that actually accepts it.
Terminal
cargo --version
cargo build --help

How to prevent it

  • Install required cargo plugins as an explicit setup step.
  • Pin the toolchain so flag availability is predictable.
  • Verify flags with --help before relying on them in CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →