{"id":"c3c5a2b2fa2bdf64","repo":"rust-lang/cargo","slug":"the-crate-dependency-could-not-be-found-at-s","errorCode":null,"errorMessage":"the crate `{dependency}` could not be found at `{source}`","messagePattern":"the crate `(.+?)` could not be found at `(.+?)`","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_add/mod.rs","lineNumber":1014,"sourceCode":"        }\n        MaybeWorkspace::Other(query) => {\n            let possibilities =\n                crate::util::block_on(registry.query_vec(&query, QueryKind::Normalized))?;\n\n            let possibilities: Vec<_> = possibilities\n                .into_iter()\n                .filter_map(|s| match s {\n                    IndexSummary::Candidate(s) => Some(s),\n                    _ => None,\n                })\n                .collect();\n\n            match possibilities.len() {\n                0 => {\n                    let source = dependency\n                        .source()\n                        .expect(\"source should be resolved before here\");\n                    anyhow::bail!(\"the crate `{dependency}` could not be found at `{source}`\")\n                }\n                1 => {\n                    let mut dep = Dependency::from(&possibilities[0]);\n                    if let Some(reg_name) = dependency.registry.as_deref() {\n                        dep = dep.set_registry(reg_name);\n                    }\n                    if let Some(Source::Path(PathSource { base, .. })) = dependency.source() {\n                        if let Some(Source::Path(dep_src)) = &mut dep.source {\n                            dep_src.base = base.clone();\n                        }\n                    }\n                    Ok(dep)\n                }\n                _ => {\n                    let source = dependency\n                        .source()\n                        .expect(\"source should be resolved before here\");\n                    anyhow::bail!(","sourceCodeStart":996,"sourceCodeEnd":1032,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_add/mod.rs#L996-L1032","documentation":"During `select_package`, cargo queries the resolved source (path or git) for packages matching the dependency. If the query returns zero candidates, it bails at mod.rs:1014 — the named crate does not exist at the given path or git source. This is distinct from a registry 404: it means the *local/git* source had no matching package.","triggerScenarios":"`cargo add --path ./wrong-dir mycrate` where that directory has no crate named `mycrate`, or `cargo add --git <url> mycrate` where the repo contains no matching package. The `select_package` match count is 0.","commonSituations":"Typo in crate name vs. package name, pointing `--path` at a subdirectory that is not a crate root, or a git repo where the package name differs from the crate binary name.","solutions":["Verify the package name with `cargo metadata --manifest-path <path>/Cargo.toml` (the `name` field) and use that exact name.","For git repos with multiple packages, let cargo infer or disambiguate: `cargo add --git <url> <exact-package-name>`.","Correct the `--path` to point at the directory containing the target crate's `Cargo.toml`."],"exampleFix":"# before\ncargo add --path ./libs wrong-name\n\n# after\ncargo add --path ./libs actual-package-name","handlingStrategy":"validation","validationCode":"// Verify the package exists at the path/git source before calling add().\nuse std::path::Path;\nfn package_exists_at(path: &Path, expected_name: &str) -> bool {\n    let manifest = path.join(\"Cargo.toml\");\n    let Ok(text) = std::fs::read_to_string(&manifest) else { return false };\n    toml_edit::ImDocument::parse(&text)\n        .ok()\n        .and_then(|d| d.as_table().get(\"package\")?.as_table()?.get(\"name\")?.as_str().map(|s| s == expected_name))\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve the exact package name from `cargo metadata` of the source before adding.","For git sources, clone-and-inspect or use `cargo add --git <url>` (auto-disambiguation) first.","Validate paths are crate roots (contain a `Cargo.toml` with a matching `[package] name`)."],"tags":["cargo-add","path","git","not-found"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}