Skip to content

Commit

Permalink
Add path to the failure to load a dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Feb 27, 2020
1 parent a07fec1 commit 1eca786
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 20 deletions.
7 changes: 5 additions & 2 deletions src/cargo/core/resolver/dep_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use std::rc::Rc;
use log::debug;

use crate::core::interning::InternedString;
use crate::core::resolver::context::Context;
use crate::core::resolver::errors::describe_path;
use crate::core::{Dependency, FeatureValue, PackageId, PackageIdSpec, Registry, Summary};
use crate::util::errors::{CargoResult, CargoResultExt};

Expand Down Expand Up @@ -197,6 +199,7 @@ impl<'a> RegistryQueryer<'a> {
/// next obvious question.
pub fn build_deps(
&mut self,
cx: &Context,
parent: Option<PackageId>,
candidate: &Summary,
opts: &ResolveOpts,
Expand All @@ -222,9 +225,9 @@ impl<'a> RegistryQueryer<'a> {
.map(|(dep, features)| {
let candidates = self.query(&dep).chain_err(|| {
anyhow::format_err!(
"failed to get `{}` as a dependency of `{}`",
"failed to get `{}` as a dependency of {}",
dep.package_name(),
candidate.package_id(),
describe_path(&cx.parents.path_to_bottom(&candidate.package_id())),
)
})?;
Ok((dep, candidates, features))
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ fn activate(

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

// Record what list of features is active for this package.
if !used_features.is_empty() {
Expand Down
8 changes: 4 additions & 4 deletions tests/testsuite/bad_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ fn bad_git_dependency() {
.with_stderr(
"\
[UPDATING] git repository `file:///`
[ERROR] failed to get `foo` as a dependency of `foo v0.0.0 [..]`
[ERROR] failed to get `foo` as a dependency of package `foo v0.0.0 [..]`
Caused by:
failed to load source for dependency `foo`
Expand Down Expand Up @@ -904,7 +904,7 @@ fn bad_source_config2() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `bar` as a dependency of `foo v0.0.0 [..]`
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.0 [..]`
Caused by:
failed to load source for dependency `bar`
Expand Down Expand Up @@ -950,7 +950,7 @@ fn bad_source_config3() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `bar` as a dependency of `foo v0.0.0 [..]`
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.0 [..]`
Caused by:
failed to load source for dependency `bar`
Expand Down Expand Up @@ -998,7 +998,7 @@ fn bad_source_config4() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `bar` as a dependency of `foo v0.0.0 ([..])`
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.0 ([..])`
Caused by:
failed to load source for dependency `bar`
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn nightly_feature_requires_nightly_in_dep() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `a` as a dependency of `b v0.0.1 ([..])`
[ERROR] failed to get `a` as a dependency of package `b v0.0.1 ([..])`
Caused by:
failed to load source for dependency `a`
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ fn git_override_requires_lockfile() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `git` as a dependency of `foo v0.0.1 ([..])`
[ERROR] failed to get `git` as a dependency of package `foo v0.0.1 ([..])`
Caused by:
failed to load source for dependency `git`
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ fn dep_with_bad_submodule() {
let expected = format!(
"\
[UPDATING] git repository [..]
[ERROR] failed to get `dep1` as a dependency of `foo v0.5.0 [..]`
[ERROR] failed to get `dep1` as a dependency of package `foo v0.5.0 [..]`
Caused by:
failed to load source for dependency `dep1`
Expand Down Expand Up @@ -2387,7 +2387,7 @@ fn invalid_git_dependency_manifest() {
.with_stderr(&format!(
"\
[UPDATING] git repository `{}`
[ERROR] failed to get `dep1` as a dependency of `foo v0.5.0 ([..])`
[ERROR] failed to get `dep1` as a dependency of package `foo v0.5.0 ([..])`
Caused by:
failed to load source for dependency `dep1`
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/git_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn http_auth_offered() {
.with_stderr_contains(&format!(
"\
[UPDATING] git repository `http://{addr}/foo/bar`
[ERROR] failed to get `bar` as a dependency of `foo v0.0.1 [..]`
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 [..]`
Caused by:
failed to load source for dependency `bar`
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 @@ -360,7 +360,7 @@ fn invalid_dir_bad() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `bar` as a dependency of `foo v0.0.1 [..]`
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 [..]`
Caused by:
failed to load source for dependency `bar`
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ fn cargo_compile_forbird_git_httpsrepo_offline() {
.build();

p.cargo("build --offline").with_status(101).with_stderr("\
[ERROR] failed to get `dep1` as a dependency of `foo v0.5.0 [..]`
[ERROR] failed to get `dep1` as a dependency of package `foo v0.5.0 [..]`
Caused by:
failed to load source for dependency `dep1`
Expand Down
65 changes: 64 additions & 1 deletion tests/testsuite/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ fn error_message_for_missing_manifest() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `bar` as a dependency of `foo v0.5.0 [..]`
[ERROR] failed to get `bar` as a dependency of package `foo v0.5.0 [..]`
Caused by:
failed to load source for dependency `bar`
Expand Down Expand Up @@ -1020,3 +1020,66 @@ fn workspace_produces_rlib() {
assert!(p.root().join("target/debug/libtop.rlib").is_file());
assert!(!p.root().join("target/debug/libfoo.rlib").is_file());
}

#[cargo_test]
fn deep_path_error() {
// Test for an error loading a path deep in the dependency graph.
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[dependencies]
a = {path="a"}
"#,
)
.file("src/lib.rs", "")
.file(
"a/Cargo.toml",
r#"
[package]
name = "a"
version = "0.1.0"
[dependencies]
b = {path="../b"}
"#,
)
.file("a/src/lib.rs", "")
.file(
"b/Cargo.toml",
r#"
[package]
name = "b"
version = "0.1.0"
[dependencies]
c = {path="../c"}
"#,
)
.file("b/src/lib.rs", "")
.build();

p.cargo("check")
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `c` as a dependency of package `b v0.1.0 [..]`
... which is depended on by `a v0.1.0 [..]`
... which is depended on by `foo v0.1.0 [..]`
Caused by:
failed to load source for dependency `c`
Caused by:
Unable to update [..]/foo/c
Caused by:
failed to read `[..]/foo/c/Cargo.toml`
Caused by:
[..]
",
)
.run();
}
2 changes: 1 addition & 1 deletion tests/testsuite/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ fn disallow_network() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `foo` as a dependency of `bar v0.5.0 [..]`
[ERROR] failed to get `foo` as a dependency of package `bar v0.5.0 [..]`
Caused by:
failed to load source for dependency `foo`
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ fn override_wrong_name() {
"\
[UPDATING] [..] index
[UPDATING] git repository [..]
[ERROR] failed to get `baz` as a dependency of `foo v0.0.1 ([..])`
[ERROR] failed to get `baz` as a dependency of package `foo v0.0.1 ([..])`
Caused by:
no matching package for override `[..]baz:0.1.0` found
Expand Down Expand Up @@ -591,7 +591,7 @@ fn override_with_nothing() {
"\
[UPDATING] [..] index
[UPDATING] git repository [..]
[ERROR] failed to get `bar` as a dependency of `foo v0.0.1 ([..])`
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..])`
Caused by:
failed to load source for dependency `bar`
Expand Down Expand Up @@ -677,7 +677,7 @@ fn multiple_specs() {
"\
[UPDATING] [..] index
[UPDATING] git repository [..]
[ERROR] failed to get `bar` as a dependency of `foo v0.0.1 ([..])`
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..])`
Caused by:
overlapping replacement specifications found:
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2223,7 +2223,7 @@ fn invalid_missing() {
.with_status(101)
.with_stderr(
"\
[ERROR] failed to get `x` as a dependency of `foo v0.1.0 [..]`
[ERROR] failed to get `x` as a dependency of package `foo v0.1.0 [..]`
Caused by:
failed to load source for dependency `x`
Expand Down

0 comments on commit 1eca786

Please sign in to comment.