Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add source replacement info when no matching package found #14715

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/cargo/core/resolver/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,13 @@ pub(super) fn activation_error(
));
msg.push('\n');
}
msg.push_str(&format!("location searched: {}\n", dep.source_id()));

let mut location_searched_msg = registry.describe_source(dep.source_id());
if location_searched_msg.is_empty() {
location_searched_msg = format!("{}", dep.source_id());
}

msg.push_str(&format!("location searched: {}\n", location_searched_msg));
msg.push_str("required by ");
msg.push_str(&describe_path_in_context(
resolver_ctx,
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6043,7 +6043,7 @@ fn avoid_dev_deps() {
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `baz` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
epage marked this conversation as resolved.
Show resolved Hide resolved
required by package `bar v0.1.0 ([ROOT]/foo)`

"#]])
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ Caused by:
no matching package found
searched package name: `baz`
perhaps you meant: bar or foo
location searched: registry `crates-io`
location searched: directory source `[ROOT]/index` (which is replacing registry `crates-io`)
required by package `bar v0.1.0`

"#]])
Expand Down Expand Up @@ -283,7 +283,7 @@ fn not_there() {
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] no matching package named `bar` found
location searched: registry `crates-io`
location searched: directory source `[ROOT]/index` (which is replacing registry `crates-io`)
required by package `foo v0.1.0 ([ROOT]/foo)`

"#]])
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/local_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn not_found() {
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] no matching package named `baz` found
location searched: registry `crates-io`
location searched: `[ROOT]/registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`

"#]])
Expand Down
20 changes: 9 additions & 11 deletions tests/testsuite/offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ fn cargo_compile_offline_not_try_update() {
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] no matching package named `not_cached_dep` found
location searched: registry `crates-io`
location searched: crates.io index
required by package `bar v0.1.0 ([ROOT]/bar)`
As a reminder, you're using offline mode (--offline) which can sometimes cause surprising resolution failures, if this error is too confusing you may wish to retry without the offline flag.

Expand All @@ -195,7 +195,7 @@ As a reminder, you're using offline mode (--offline) which can sometimes cause s
p.change_file(".cargo/config.toml", "net.offline = true");
p.cargo("check").with_status(101).with_stderr_data(str![[r#"
[ERROR] no matching package named `not_cached_dep` found
location searched: registry `crates-io`
location searched: crates.io index
required by package `bar v0.1.0 ([ROOT]/bar)`
As a reminder, you're using offline mode (--offline) which can sometimes cause surprising resolution failures, if this error is too confusing you may wish to retry without the offline flag.

Expand Down Expand Up @@ -383,18 +383,16 @@ fn update_offline_not_cached() {
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("update --offline")
.with_status(101)
.with_stderr_data(
"\
.with_stderr_data(str![["
[ERROR] no matching package named `bar` found
location searched: registry `crates-io`
location searched: [..]
required by package `foo v0.0.1 ([ROOT]/foo)`
As a reminder, you're using offline mode (--offline) which can sometimes cause \
surprising resolution failures, if this error is too confusing you may wish to \
retry without the offline flag.
",
)
As a reminder, you're using offline mode (--offline) which can sometimes cause surprising resolution failures, if this error is too confusing you may wish to retry without the offline flag.

"]])
.run();
}

Expand Down Expand Up @@ -756,7 +754,7 @@ fn main(){
.with_stderr_data(
str![[r#"
[ERROR] no matching package named `present_dep` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.1.0 ([ROOT]/foo)`
As a reminder, you're using offline mode (--offline) which can sometimes cause surprising resolution failures, if this error is too confusing you may wish to retry without the offline flag.

Expand Down
12 changes: 6 additions & 6 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5312,7 +5312,7 @@ fn workspace_with_local_deps() {

Caused by:
no matching package named `level2` found
location searched: registry `crates-io`
location searched: crates.io index
required by package `level1 v0.0.1 ([ROOT]/foo/level1)`

"#]])
Expand Down Expand Up @@ -5496,7 +5496,7 @@ fn workspace_with_local_deps_packaging_one_fails() {

Caused by:
no matching package named `level2` found
location searched: registry `crates-io`
location searched: crates.io index
required by package `level1 v0.0.1 ([ROOT]/foo/target/package/level1-0.0.1)`

"#]])
Expand All @@ -5523,7 +5523,7 @@ fn workspace_with_local_deps_packaging_one_fails_nightly() {

Caused by:
no matching package named `level2` found
location searched: registry `crates-io`
location searched: crates.io index
required by package `level1 v0.0.1 ([ROOT]/foo/target/package/level1-0.0.1)`

"#]])
Expand Down Expand Up @@ -5589,7 +5589,7 @@ fn workspace_with_local_deps_packaging_one_bin_fails() {

Caused by:
no matching package named `level2` found
location searched: registry `crates-io`
location searched: crates.io index
required by package `level1 v0.0.1 ([ROOT]/foo/level1)`

"#]])
Expand Down Expand Up @@ -5809,7 +5809,7 @@ fn workspace_with_local_deps_index_mismatch() {

Caused by:
no matching package named `level2` found
location searched: registry `crates-io`
location searched: crates.io index
required by package `level1 v0.0.1 ([ROOT]/foo/level1)`

"#]])
Expand Down Expand Up @@ -6620,7 +6620,7 @@ fn unpublishable_dependency() {

Caused by:
no matching package named `dep` found
location searched: registry `alternative`
location searched: `alternative` index
required by package `main v0.0.1 ([ROOT]/foo/main)`

"#]])
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3932,7 +3932,7 @@ fn workspace_missing_dependency() {

Caused by:
no matching package named `a` found
location searched: registry `crates-io`
location searched: crates.io index
required by package `b v0.0.1 ([ROOT]/foo/target/package/b-0.0.1)`

"#]])
Expand Down
34 changes: 17 additions & 17 deletions tests/testsuite/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn nonexistent_http() {
nonexistent(str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `nonexistent` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`

"#]]);
Expand All @@ -178,7 +178,7 @@ fn nonexistent_git() {
nonexistent(str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `nonexistent` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`

"#]]);
Expand Down Expand Up @@ -218,7 +218,7 @@ fn wrong_case_http() {
[ERROR] no matching package found
searched package name: `Init`
perhaps you meant: init
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`

"#]]);
Expand All @@ -231,7 +231,7 @@ fn wrong_case_git() {
[ERROR] no matching package found
searched package name: `Init`
perhaps you meant: init
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`

"#]]);
Expand Down Expand Up @@ -272,7 +272,7 @@ fn mis_hyphenated_http() {
[ERROR] no matching package found
searched package name: `mis_hyphenated`
perhaps you meant: mis-hyphenated
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`

"#]]);
Expand All @@ -285,7 +285,7 @@ fn mis_hyphenated_git() {
[ERROR] no matching package found
searched package name: `mis_hyphenated`
perhaps you meant: mis-hyphenated
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`

"#]]);
Expand Down Expand Up @@ -468,7 +468,7 @@ fn update_registry_http() {
str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `notyet` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`

"#]],
Expand All @@ -491,7 +491,7 @@ fn update_registry_git() {
str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `notyet` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`

"#]],
Expand Down Expand Up @@ -551,7 +551,7 @@ fn package_with_path_deps_http() {

Caused by:
no matching package named `notyet` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`

"#]],
Expand Down Expand Up @@ -580,7 +580,7 @@ fn package_with_path_deps_git() {

Caused by:
no matching package named `notyet` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`

"#]],
Expand Down Expand Up @@ -925,7 +925,7 @@ fn yanks_in_lockfiles_are_ok_http() {
str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `bar` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`

"#]],
Expand All @@ -942,7 +942,7 @@ fn yanks_in_lockfiles_are_ok_git() {
str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `bar` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`

"#]],
Expand Down Expand Up @@ -994,7 +994,7 @@ fn yanks_in_lockfiles_are_ok_for_other_update_http() {
str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `bar` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`

"#]],
Expand All @@ -1017,7 +1017,7 @@ fn yanks_in_lockfiles_are_ok_for_other_update_git() {
str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `bar` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`

"#]],
Expand Down Expand Up @@ -3226,7 +3226,7 @@ fn unknown_index_version_error() {
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `bar` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.1.0 ([ROOT]/foo)`

"#]])
Expand Down Expand Up @@ -3769,7 +3769,7 @@ foo v0.1.0 ([ROOT]/foo)
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `bar` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.1.0 ([ROOT]/foo)`

"#]])
Expand Down Expand Up @@ -3863,7 +3863,7 @@ fn not_found_permutations() {
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `a-b_c` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.0.1 ([ROOT]/foo)`

"#]])
Expand Down
43 changes: 43 additions & 0 deletions tests/testsuite/source_replacement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,46 @@ fn source_replacement_with_registry_url() {
"#]])
.run();
}

#[cargo_test]
fn source_replacement_with_no_package_in_directoy() {
epage marked this conversation as resolved.
Show resolved Hide resolved
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2021"

[dependencies]
bar = { version = "^0.8.9" }
"#,
)
.file("src/lib.rs", "")
.build();

let root = paths::root();
t!(fs::create_dir(&root.join("vendor")));

let crates_io = setup_replacement(&format!(
r#"
[source.crates-io]
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "vendor"
"#
));

p.cargo("build")
.replace_crates_io(crates_io.index_url())
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] no matching package named `bar` found
location searched: directory source `[ROOT]/vendor` (which is replacing registry `crates-io`)
required by package `foo v0.1.0 ([ROOT]/foo)`

"#]])
.run();
}
6 changes: 3 additions & 3 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ perhaps a crate was updated and forgotten to be re-vendored?
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `serde` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `bar v0.0.1 ([ROOT]/foo)`

"#]])
Expand Down Expand Up @@ -997,7 +997,7 @@ Caused by:
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `bar` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.1.0 ([ROOT]/foo)`

"#]])
Expand All @@ -1017,7 +1017,7 @@ required by package `foo v0.1.0 ([ROOT]/foo)`
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `bar` found
location searched: registry `crates-io`
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
required by package `foo v0.1.0 ([ROOT]/foo)`

"#]])
Expand Down