{"record":{"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":1033,"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":1015,"sourceCodeEnd":1051,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/ops/cargo_add/mod.rs#L1015-L1051","documentation":"Thrown by cargo_add's select_package after querying the registry/path/git source for a dependency and receiving zero Candidate summaries. The dependency's source was already resolved (the expect proves it), but no index entry matched the crate name at that source. This is the 'add' analog of a 404: the name does not exist where you told cargo to look.","triggerScenarios":"Running `cargo add <name> --path <dir>` or `--git <url>` where the directory/repository contains no package with that name, or `cargo add <name>` against a private/alternate registry that does not index the crate. Also triggered by a typo in the crate name passed to a path/git source, or by pointing --path at a subdirectory that lacks Cargo.toml.","commonSituations":"Renaming a crate in the source repo but adding it by its old name; pointing --git at a monorepo and forgetting the package lives in a subdir; using a sparse/git registry mirror that has not yet replicated the crate; network/registry-index fetch silently returning an empty result set.","solutions":["Verify the package name spelling matches the `name` field in the source's Cargo.toml, not the directory or git URL.","For --path, confirm the path points at the directory containing the crate's Cargo.toml (not a parent or sibling).","For --git, list packages in the repo first: `cargo add --git <url>` and, if multiple, append the exact package name as shown in the disambiguation hint.","If using a custom registry, check the crate is published there (`cargo search <name> --registry <name>`) and that the registry index is up to date."],"exampleFix":"// before\ncargo add mycrate --path ./sibling\n// after (path containing Cargo.toml)\ncargo add mycrate --path ./sibling/mycrate","handlingStrategy":"validation","validationCode":"// Before calling cargo add programmatically, confirm the source contains the crate.\nuse std::path::Path;\nfn path_has_crate(dir: &Path, name: &str) -> bool {\n    let manifest = dir.join(\"Cargo.toml\");\n    std::fs::read_to_string(manifest)\n        .map(|t| t.contains(&format!(\"name = \\\"{name}\\\"\")))\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always confirm the source directory/git repo actually contains a Cargo.toml with the expected package name before adding.","Prefer `cargo add --git <url> <exact-package-name>` over bare URL adds.","In scripts, resolve the package name from metadata before invoking `cargo add`."],"tags":["cargo-add","dependency-resolution","path-source","git-source"],"backgroundTag":null,"analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}