Skip to content

Commit 9ae6d41

Browse files
committed
Auto merge of #9368 - weihanglo:issue-9319, r=ehuss
fix: better error message when dependency/workspace member missing May fix #9319
2 parents 2c6e748 + 9c0d865 commit 9ae6d41

File tree

2 files changed

+71
-9
lines changed

2 files changed

+71
-9
lines changed

src/cargo/core/workspace.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,13 @@ impl<'cfg> Workspace<'cfg> {
645645
};
646646

647647
for path in &members_paths {
648-
self.find_path_deps(&path.join("Cargo.toml"), &root_manifest_path, false)?;
648+
self.find_path_deps(&path.join("Cargo.toml"), &root_manifest_path, false)
649+
.with_context(|| {
650+
format!(
651+
"failed to load manifest for workspace member `{}`",
652+
path.display()
653+
)
654+
})?;
649655
}
650656

651657
if let Some(default) = default_members_paths {
@@ -719,14 +725,15 @@ impl<'cfg> Workspace<'cfg> {
719725
self.member_ids.insert(pkg.package_id());
720726
pkg.dependencies()
721727
.iter()
722-
.map(|d| d.source_id())
723-
.filter(|d| d.is_path())
724-
.filter_map(|d| d.url().to_file_path().ok())
725-
.map(|p| p.join("Cargo.toml"))
728+
.map(|d| (d.source_id(), d.package_name()))
729+
.filter(|(s, _)| s.is_path())
730+
.filter_map(|(s, n)| s.url().to_file_path().ok().map(|p| (p, n)))
731+
.map(|(p, n)| (p.join("Cargo.toml"), n))
726732
.collect::<Vec<_>>()
727733
};
728-
for candidate in candidates {
729-
self.find_path_deps(&candidate, root_manifest, true)
734+
for (path, name) in candidates {
735+
self.find_path_deps(&path, root_manifest, true)
736+
.with_context(|| format!("failed to load manifest for dependency `{}`", name))
730737
.map_err(|err| ManifestError::new(err, manifest_path.clone()))?;
731738
}
732739
Ok(())

tests/testsuite/workspaces.rs

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ fn invalid_members() {
408408
.with_status(101)
409409
.with_stderr(
410410
"\
411-
error: failed to read `[..]Cargo.toml`
411+
[ERROR] failed to load manifest for workspace member `[..]/foo`
412+
413+
Caused by:
414+
failed to read `[..]foo/foo/Cargo.toml`
412415
413416
Caused by:
414417
[..]
@@ -1869,7 +1872,10 @@ fn glob_syntax_invalid_members() {
18691872
.with_status(101)
18701873
.with_stderr(
18711874
"\
1872-
error: failed to read `[..]Cargo.toml`
1875+
[ERROR] failed to load manifest for workspace member `[..]/crates/bar`
1876+
1877+
Caused by:
1878+
failed to read `[..]foo/crates/bar/Cargo.toml`
18731879
18741880
Caused by:
18751881
[..]
@@ -2318,6 +2324,55 @@ Caused by:
23182324
.run();
23192325
}
23202326

2327+
#[cargo_test]
2328+
fn member_dep_missing() {
2329+
// Make sure errors are not suppressed with -q.
2330+
let p = project()
2331+
.file(
2332+
"Cargo.toml",
2333+
r#"
2334+
[project]
2335+
name = "foo"
2336+
version = "0.1.0"
2337+
2338+
[workspace]
2339+
members = ["bar"]
2340+
"#,
2341+
)
2342+
.file("src/main.rs", "fn main() {}")
2343+
.file(
2344+
"bar/Cargo.toml",
2345+
r#"
2346+
[project]
2347+
name = "bar"
2348+
version = "0.1.0"
2349+
2350+
[dependencies]
2351+
baz = { path = "baz" }
2352+
"#,
2353+
)
2354+
.file("bar/src/main.rs", "fn main() {}")
2355+
.build();
2356+
2357+
p.cargo("build -q")
2358+
.with_status(101)
2359+
.with_stderr(
2360+
"\
2361+
[ERROR] failed to load manifest for workspace member `[..]/bar`
2362+
2363+
Caused by:
2364+
failed to load manifest for dependency `baz`
2365+
2366+
Caused by:
2367+
failed to read `[..]foo/bar/baz/Cargo.toml`
2368+
2369+
Caused by:
2370+
[..]
2371+
",
2372+
)
2373+
.run();
2374+
}
2375+
23212376
#[cargo_test]
23222377
fn simple_primary_package_env_var() {
23232378
let is_primary_package = r#"

0 commit comments

Comments
 (0)