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.
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.
- uses: taiki-e/install-action@v2
with:
tool: cargo-nextest
- run: cargo nextest runCheck the flag against the right command and version
- Run
cargo <subcommand> --helpto confirm the flag exists there. - Check
cargo --version; a newer flag may not exist on an older toolchain. - Move the flag to the subcommand that actually accepts it.
cargo --version
cargo build --helpHow to prevent it
- Install required cargo plugins as an explicit setup step.
- Pin the toolchain so flag availability is predictable.
- Verify flags with
--helpbefore relying on them in CI.