Skip to content

Commit

Permalink
fix: more error context for missing dep of workspace member
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Apr 17, 2021
1 parent 832fff8 commit 9c0d865
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,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
49 changes: 49 additions & 0 deletions tests/testsuite/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2324,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 9c0d865

Please sign in to comment.