Skip to content

Commit

Permalink
Auto merge of #9368 - weihanglo:issue-9319, r=ehuss
Browse files Browse the repository at this point in the history
fix: better error message when dependency/workspace member missing

May fix #9319
  • Loading branch information
bors committed Apr 19, 2021
2 parents 2c6e748 + 9c0d865 commit 9ae6d41
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 9 deletions.
21 changes: 14 additions & 7 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,13 @@ impl<'cfg> Workspace<'cfg> {
};

for path in &members_paths {
self.find_path_deps(&path.join("Cargo.toml"), &root_manifest_path, false)?;
self.find_path_deps(&path.join("Cargo.toml"), &root_manifest_path, false)
.with_context(|| {
format!(
"failed to load manifest for workspace member `{}`",
path.display()
)
})?;
}

if let Some(default) = default_members_paths {
Expand Down Expand Up @@ -719,14 +725,15 @@ impl<'cfg> Workspace<'cfg> {
self.member_ids.insert(pkg.package_id());
pkg.dependencies()
.iter()
.map(|d| d.source_id())
.filter(|d| d.is_path())
.filter_map(|d| d.url().to_file_path().ok())
.map(|p| p.join("Cargo.toml"))
.map(|d| (d.source_id(), d.package_name()))
.filter(|(s, _)| s.is_path())
.filter_map(|(s, n)| s.url().to_file_path().ok().map(|p| (p, n)))
.map(|(p, n)| (p.join("Cargo.toml"), n))
.collect::<Vec<_>>()
};
for candidate in candidates {
self.find_path_deps(&candidate, root_manifest, true)
for (path, name) in candidates {
self.find_path_deps(&path, root_manifest, true)
.with_context(|| format!("failed to load manifest for dependency `{}`", name))
.map_err(|err| ManifestError::new(err, manifest_path.clone()))?;
}
Ok(())
Expand Down
59 changes: 57 additions & 2 deletions tests/testsuite/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,10 @@ fn invalid_members() {
.with_status(101)
.with_stderr(
"\
error: failed to read `[..]Cargo.toml`
[ERROR] failed to load manifest for workspace member `[..]/foo`
Caused by:
failed to read `[..]foo/foo/Cargo.toml`
Caused by:
[..]
Expand Down Expand Up @@ -1869,7 +1872,10 @@ fn glob_syntax_invalid_members() {
.with_status(101)
.with_stderr(
"\
error: failed to read `[..]Cargo.toml`
[ERROR] failed to load manifest for workspace member `[..]/crates/bar`
Caused by:
failed to read `[..]foo/crates/bar/Cargo.toml`
Caused by:
[..]
Expand Down Expand Up @@ -2318,6 +2324,55 @@ Caused by:
.run();
}

#[cargo_test]
fn member_dep_missing() {
// Make sure errors are not suppressed with -q.
let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.1.0"
[workspace]
members = ["bar"]
"#,
)
.file("src/main.rs", "fn main() {}")
.file(
"bar/Cargo.toml",
r#"
[project]
name = "bar"
version = "0.1.0"
[dependencies]
baz = { path = "baz" }
"#,
)
.file("bar/src/main.rs", "fn main() {}")
.build();

p.cargo("build -q")
.with_status(101)
.with_stderr(
"\
[ERROR] failed to load manifest for workspace member `[..]/bar`
Caused by:
failed to load manifest for dependency `baz`
Caused by:
failed to read `[..]foo/bar/baz/Cargo.toml`
Caused by:
[..]
",
)
.run();
}

#[cargo_test]
fn simple_primary_package_env_var() {
let is_primary_package = r#"
Expand Down

0 comments on commit 9ae6d41

Please sign in to comment.