{"id":"b4f4683b8d981fc3","repo":"rust-lang/cargo","slug":"package-spec-requires-a-spec-format-value-w","errorCode":null,"errorMessage":"\"--package <SPEC>\" requires a SPEC format value, which can be any package ID specifier in the dependency graph.\nRun `cargo help pkgid` for more information about SPEC format.","messagePattern":"\"--package <SPEC>\" requires a SPEC format value, which can be any package ID specifier in the dependency graph\\.\nRun `cargo help pkgid` for more information about SPEC format\\.","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/util/command_prelude.rs","lineNumber":861,"sourceCode":"                self._values_of(\"example\"),\n                self.flag(\"examples\"),\n                self._values_of(\"bench\"),\n                self.flag(\"benches\"),\n                self.flag(\"all-targets\"),\n            ),\n            target_rustdoc_args: None,\n            target_rustc_args: None,\n            target_rustc_crate_types: None,\n            rustdoc_document_private_items: false,\n            honor_rust_version: self.honor_rust_version(),\n        };\n\n        if let Some(ws) = workspace {\n            self.check_optional_opts(ws, &opts)?;\n        } else if self.is_present_with_zero_values(\"package\") {\n            // As for cargo 0.50.0, this won't occur but if someone sneaks in\n            // we can still provide this informative message for them.\n            anyhow::bail!(\n                \"\\\"--package <SPEC>\\\" requires a SPEC format value, \\\n                which can be any package ID specifier in the dependency graph.\\n\\\n                Run `cargo help pkgid` for more information about SPEC format.\"\n            )\n        }\n\n        Ok(opts)\n    }\n\n    fn cli_features(&self) -> CargoResult<CliFeatures> {\n        CliFeatures::from_command_line(\n            &self._values_of(\"features\"),\n            self.flag(\"all-features\"),\n            !self.flag(\"no-default-features\"),\n        )\n    }\n\n    fn compile_options_for_single_package(","sourceCodeStart":843,"sourceCodeEnd":879,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/util/command_prelude.rs#L843-L879","documentation":"In compile_options, after building CompileOptions, if no workspace is present but `--package` was passed with zero values (is_present_with_zero_values), Cargo bails because `-p`/`--package` requires a SPEC argument naming a package ID specifier in the dependency graph. As the comment notes, since cargo 0.50.0 clap normally prevents this, but the guard catches any path that sneaks through.","triggerScenarios":"Invoking a compile-like subcommand with `--package` (or `-p`) but no value, in a context where clap did not enforce the required value — e.g. calling the argument-parsing path programmatically with an empty package flag, or a shell alias that drops the value.","commonSituations":"A shell alias or script that runs `cargo build -p` and accidentally omits the package name; programmatic construction of ArgMatches that marks `package` present with zero values.","solutions":["Supply a package SPEC: `cargo build -p my-crate` (or `-p my-crate:0.1.0`).","If you want all workspace packages, use `--workspace` / `--all` instead of bare `-p`.","Inspect the command/script that builds the cargo invocation and ensure the `-p` value is not stripped by quoting/word-splitting."],"exampleFix":"# before\ncargo build -p\n\n# after\ncargo build -p my-crate","handlingStrategy":"validation","validationCode":"// If building the cargo ArgMatches programmatically, never mark `package`\n// present without a value.\nfn packages_arg(matches: &ArgMatches) -> Vec<String> {\n    let v = matches._values_of(\"package\");\n    assert!(!v.is_empty(), \"--package requires a SPEC value\");\n    v\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = cli.compile_options(...) {\n    if e.to_string().contains(\"requires a SPEC format value\") {\n        eprintln!(\"usage: cargo build -p <SPEC>\");\n    }\n    return Err(e);\n}","preventionTips":["When scripting cargo invocations, always pair `-p` with a package name.","Prefer `--workspace` when you want all packages.","Validate the generated command line by echoing it before exec."],"tags":["cli","package-selection","argument-parsing"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}