{"id":"d8625cd0a1776426","repo":"rust-lang/cargo","slug":"package-s-not-found-in-workspace","errorCode":null,"errorMessage":"{}package(s) `{}` not found in workspace `{}`","messagePattern":"(.+?)package\\(s\\) `(.+?)` not found in workspace `(.+?)`","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_compile/packages.rs","lineNumber":184,"sourceCode":"    /// specific package in the workspace.\n    pub fn needs_spec_flag(&self, ws: &Workspace<'_>) -> bool {\n        match self {\n            Packages::Default => ws.default_members().count() > 1,\n            Packages::All(_) => ws.members().count() > 1,\n            Packages::Packages(_) => true,\n            Packages::OptOut(_) => true,\n        }\n    }\n}\n\n/// Emits \"package not found\" error.\nfn emit_package_not_found(\n    ws: &Workspace<'_>,\n    opt_names: BTreeSet<String>,\n    opt_out: bool,\n) -> CargoResult<()> {\n    if !opt_names.is_empty() {\n        anyhow::bail!(\n            \"{}package(s) `{}` not found in workspace `{}`\",\n            if opt_out { \"excluded \" } else { \"\" },\n            opt_names.into_iter().collect::<Vec<_>>().join(\", \"),\n            ws.root().display(),\n        )\n    }\n    Ok(())\n}\n\n/// Emits \"glob pattern not found\" error.\nfn emit_pattern_not_found(\n    ws: &Workspace<'_>,\n    opt_patterns: Vec<(glob::Pattern, bool)>,\n    opt_out: bool,\n) -> CargoResult<()> {\n    let not_matched = opt_patterns\n        .iter()\n        .filter(|(_, matched)| !*matched)","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_compile/packages.rs#L166-L202","documentation":"Thrown by emit_package_not_found (src/ops/cargo_compile/packages.rs:178-192) when one or more exact package-name specs passed via -p / --exclude do not match any workspace member (or, with the prefix, any excluded member). The names that failed to match are listed.","triggerScenarios":"`cargo build -p typo-name`, `cargo test --workspace --exclude ghost` (prefixes the message with 'excluded '), or any Packages selection where an exact PackageIdSpec does not resolve to a workspace member. The remaining opt_names set is non-empty at bail time.","commonSituations":"Typos in package names. Renaming a crate without updating CI scripts. Referring to a dependency by its source name rather than the workspace member name. Stale references after a crate was removed from the workspace.","solutions":["Run `cargo metadata --no-deps` (or `ls` the workspace) to list the exact member names and correct the spelling.","Update the -p / --exclude argument to the real crate name (note: use the package name, not the path).","If the crate was removed, delete the now-invalid reference from scripts/CI.","Use a glob pattern only if you intended a pattern; otherwise exact names must match."],"exampleFix":"# before\ncargo build -p mycrate-typo\n\n# after\ncargo build -p mycrate","handlingStrategy":"validation","validationCode":"// Verify each exact -p / --exclude name is a workspace member.\nfn known_members(ws: &Workspace) -> std::collections::HashSet<String> {\n    ws.members().map(|m| m.name().as_str().to_string()).collect()\n}\n// let members = known_members(ws);\n// for n in &specs { assert!(members.contains(n), \"unknown package {}\", n); }","typeGuard":"fn all_names_are_members(ws: &Workspace, names: &[String]) -> bool {\n    let members: std::collections::HashSet<_> =\n        ws.members().map(|m| m.name().as_str().to_string()).collect();\n    names.iter().all(|n| members.contains(n))\n}","tryCatchPattern":"if let Err(e) = pkgs.get_packages(ws) {\n    if e.to_string().contains(\"not found in workspace\") {\n        eprintln!(\"run `cargo metadata --no-deps` to list valid member names\");\n    }\n    return Err(e);\n}","preventionTips":["Source package names from `cargo metadata` in automation to avoid typos.","Add a pre-flight check that every -p name resolves to a member."],"tags":["cargo","workspace","package-selection","cli","manifest"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}