Skip to content

Commit 1eca786

Browse files
committed
Add path to the failure to load a dependency.
1 parent a07fec1 commit 1eca786

13 files changed

+86
-20
lines changed

src/cargo/core/resolver/dep_cache.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use std::rc::Rc;
1616
use log::debug;
1717

1818
use crate::core::interning::InternedString;
19+
use crate::core::resolver::context::Context;
20+
use crate::core::resolver::errors::describe_path;
1921
use crate::core::{Dependency, FeatureValue, PackageId, PackageIdSpec, Registry, Summary};
2022
use crate::util::errors::{CargoResult, CargoResultExt};
2123

@@ -197,6 +199,7 @@ impl<'a> RegistryQueryer<'a> {
197199
/// next obvious question.
198200
pub fn build_deps(
199201
&mut self,
202+
cx: &Context,
200203
parent: Option<PackageId>,
201204
candidate: &Summary,
202205
opts: &ResolveOpts,
@@ -222,9 +225,9 @@ impl<'a> RegistryQueryer<'a> {
222225
.map(|(dep, features)| {
223226
let candidates = self.query(&dep).chain_err(|| {
224227
anyhow::format_err!(
225-
"failed to get `{}` as a dependency of `{}`",
228+
"failed to get `{}` as a dependency of {}",
226229
dep.package_name(),
227-
candidate.package_id(),
230+
describe_path(&cx.parents.path_to_bottom(&candidate.package_id())),
228231
)
229232
})?;
230233
Ok((dep, candidates, features))

src/cargo/core/resolver/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ fn activate(
656656

657657
let now = Instant::now();
658658
let (used_features, deps) =
659-
&*registry.build_deps(parent.map(|p| p.0.package_id()), &candidate, &opts)?;
659+
&*registry.build_deps(cx, parent.map(|p| p.0.package_id()), &candidate, &opts)?;
660660

661661
// Record what list of features is active for this package.
662662
if !used_features.is_empty() {

tests/testsuite/bad_config.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ fn bad_git_dependency() {
368368
.with_stderr(
369369
"\
370370
[UPDATING] git repository `file:///`
371-
[ERROR] failed to get `foo` as a dependency of `foo v0.0.0 [..]`
371+
[ERROR] failed to get `foo` as a dependency of package `foo v0.0.0 [..]`
372372
373373
Caused by:
374374
failed to load source for dependency `foo`
@@ -904,7 +904,7 @@ fn bad_source_config2() {
904904
.with_status(101)
905905
.with_stderr(
906906
"\
907-
[ERROR] failed to get `bar` as a dependency of `foo v0.0.0 [..]`
907+
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.0 [..]`
908908
909909
Caused by:
910910
failed to load source for dependency `bar`
@@ -950,7 +950,7 @@ fn bad_source_config3() {
950950
.with_status(101)
951951
.with_stderr(
952952
"\
953-
[ERROR] failed to get `bar` as a dependency of `foo v0.0.0 [..]`
953+
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.0 [..]`
954954
955955
Caused by:
956956
failed to load source for dependency `bar`
@@ -998,7 +998,7 @@ fn bad_source_config4() {
998998
.with_status(101)
999999
.with_stderr(
10001000
"\
1001-
[ERROR] failed to get `bar` as a dependency of `foo v0.0.0 ([..])`
1001+
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.0 ([..])`
10021002
10031003
Caused by:
10041004
failed to load source for dependency `bar`

tests/testsuite/cargo_features.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn nightly_feature_requires_nightly_in_dep() {
199199
.with_status(101)
200200
.with_stderr(
201201
"\
202-
[ERROR] failed to get `a` as a dependency of `b v0.0.1 ([..])`
202+
[ERROR] failed to get `a` as a dependency of package `b v0.0.1 ([..])`
203203
204204
Caused by:
205205
failed to load source for dependency `a`

tests/testsuite/directory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ fn git_override_requires_lockfile() {
652652
.with_status(101)
653653
.with_stderr(
654654
"\
655-
[ERROR] failed to get `git` as a dependency of `foo v0.0.1 ([..])`
655+
[ERROR] failed to get `git` as a dependency of package `foo v0.0.1 ([..])`
656656
657657
Caused by:
658658
failed to load source for dependency `git`

tests/testsuite/git.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ fn dep_with_bad_submodule() {
931931
let expected = format!(
932932
"\
933933
[UPDATING] git repository [..]
934-
[ERROR] failed to get `dep1` as a dependency of `foo v0.5.0 [..]`
934+
[ERROR] failed to get `dep1` as a dependency of package `foo v0.5.0 [..]`
935935
936936
Caused by:
937937
failed to load source for dependency `dep1`
@@ -2387,7 +2387,7 @@ fn invalid_git_dependency_manifest() {
23872387
.with_stderr(&format!(
23882388
"\
23892389
[UPDATING] git repository `{}`
2390-
[ERROR] failed to get `dep1` as a dependency of `foo v0.5.0 ([..])`
2390+
[ERROR] failed to get `dep1` as a dependency of package `foo v0.5.0 ([..])`
23912391
23922392
Caused by:
23932393
failed to load source for dependency `dep1`

tests/testsuite/git_auth.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn http_auth_offered() {
133133
.with_stderr_contains(&format!(
134134
"\
135135
[UPDATING] git repository `http://{addr}/foo/bar`
136-
[ERROR] failed to get `bar` as a dependency of `foo v0.0.1 [..]`
136+
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 [..]`
137137
138138
Caused by:
139139
failed to load source for dependency `bar`

tests/testsuite/local_registry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ fn invalid_dir_bad() {
360360
.with_status(101)
361361
.with_stderr(
362362
"\
363-
[ERROR] failed to get `bar` as a dependency of `foo v0.0.1 [..]`
363+
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 [..]`
364364
365365
Caused by:
366366
failed to load source for dependency `bar`

tests/testsuite/offline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ fn cargo_compile_forbird_git_httpsrepo_offline() {
270270
.build();
271271

272272
p.cargo("build --offline").with_status(101).with_stderr("\
273-
[ERROR] failed to get `dep1` as a dependency of `foo v0.5.0 [..]`
273+
[ERROR] failed to get `dep1` as a dependency of package `foo v0.5.0 [..]`
274274
275275
Caused by:
276276
failed to load source for dependency `dep1`

tests/testsuite/path.rs

+64-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ fn error_message_for_missing_manifest() {
521521
.with_status(101)
522522
.with_stderr(
523523
"\
524-
[ERROR] failed to get `bar` as a dependency of `foo v0.5.0 [..]`
524+
[ERROR] failed to get `bar` as a dependency of package `foo v0.5.0 [..]`
525525
526526
Caused by:
527527
failed to load source for dependency `bar`
@@ -1020,3 +1020,66 @@ fn workspace_produces_rlib() {
10201020
assert!(p.root().join("target/debug/libtop.rlib").is_file());
10211021
assert!(!p.root().join("target/debug/libfoo.rlib").is_file());
10221022
}
1023+
1024+
#[cargo_test]
1025+
fn deep_path_error() {
1026+
// Test for an error loading a path deep in the dependency graph.
1027+
let p = project()
1028+
.file(
1029+
"Cargo.toml",
1030+
r#"
1031+
[package]
1032+
name = "foo"
1033+
version = "0.1.0"
1034+
[dependencies]
1035+
a = {path="a"}
1036+
"#,
1037+
)
1038+
.file("src/lib.rs", "")
1039+
.file(
1040+
"a/Cargo.toml",
1041+
r#"
1042+
[package]
1043+
name = "a"
1044+
version = "0.1.0"
1045+
[dependencies]
1046+
b = {path="../b"}
1047+
"#,
1048+
)
1049+
.file("a/src/lib.rs", "")
1050+
.file(
1051+
"b/Cargo.toml",
1052+
r#"
1053+
[package]
1054+
name = "b"
1055+
version = "0.1.0"
1056+
[dependencies]
1057+
c = {path="../c"}
1058+
"#,
1059+
)
1060+
.file("b/src/lib.rs", "")
1061+
.build();
1062+
1063+
p.cargo("check")
1064+
.with_status(101)
1065+
.with_stderr(
1066+
"\
1067+
[ERROR] failed to get `c` as a dependency of package `b v0.1.0 [..]`
1068+
... which is depended on by `a v0.1.0 [..]`
1069+
... which is depended on by `foo v0.1.0 [..]`
1070+
1071+
Caused by:
1072+
failed to load source for dependency `c`
1073+
1074+
Caused by:
1075+
Unable to update [..]/foo/c
1076+
1077+
Caused by:
1078+
failed to read `[..]/foo/c/Cargo.toml`
1079+
1080+
Caused by:
1081+
[..]
1082+
",
1083+
)
1084+
.run();
1085+
}

tests/testsuite/registry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ fn disallow_network() {
15581558
.with_status(101)
15591559
.with_stderr(
15601560
"\
1561-
[ERROR] failed to get `foo` as a dependency of `bar v0.5.0 [..]`
1561+
[ERROR] failed to get `foo` as a dependency of package `bar v0.5.0 [..]`
15621562
15631563
Caused by:
15641564
failed to load source for dependency `foo`

tests/testsuite/replace.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ fn override_wrong_name() {
544544
"\
545545
[UPDATING] [..] index
546546
[UPDATING] git repository [..]
547-
[ERROR] failed to get `baz` as a dependency of `foo v0.0.1 ([..])`
547+
[ERROR] failed to get `baz` as a dependency of package `foo v0.0.1 ([..])`
548548
549549
Caused by:
550550
no matching package for override `[..]baz:0.1.0` found
@@ -591,7 +591,7 @@ fn override_with_nothing() {
591591
"\
592592
[UPDATING] [..] index
593593
[UPDATING] git repository [..]
594-
[ERROR] failed to get `bar` as a dependency of `foo v0.0.1 ([..])`
594+
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..])`
595595
596596
Caused by:
597597
failed to load source for dependency `bar`
@@ -677,7 +677,7 @@ fn multiple_specs() {
677677
"\
678678
[UPDATING] [..] index
679679
[UPDATING] git repository [..]
680-
[ERROR] failed to get `bar` as a dependency of `foo v0.0.1 ([..])`
680+
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..])`
681681
682682
Caused by:
683683
overlapping replacement specifications found:

tests/testsuite/workspaces.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2223,7 +2223,7 @@ fn invalid_missing() {
22232223
.with_status(101)
22242224
.with_stderr(
22252225
"\
2226-
[ERROR] failed to get `x` as a dependency of `foo v0.1.0 [..]`
2226+
[ERROR] failed to get `x` as a dependency of package `foo v0.1.0 [..]`
22272227
22282228
Caused by:
22292229
failed to load source for dependency `x`

0 commit comments

Comments
 (0)