Skip to content

Commit e87c50e

Browse files
committed
prepare: report a structured error when a dependency is missing
1 parent 76196c3 commit e87c50e

File tree

7 files changed

+55
-0
lines changed

7 files changed

+55
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## Unreleased
77

8+
### Added
9+
10+
- New variant `PrepareError::MissingDependencies`, returned during the prepare
11+
step when a dependency does not exist.
12+
813
### Changed
914

1015
- Path dependencies are no longer removed from `Cargo.toml` during the prepare

src/prepare.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ impl<'a> Prepare<'a> {
9696
}
9797

9898
let mut yanked_deps = false;
99+
let mut missing_deps = false;
99100
let mut cmd = Command::new(self.workspace, self.toolchain.cargo()).args(&[
100101
"generate-lockfile",
101102
"--manifest-path",
@@ -111,13 +112,20 @@ impl<'a> Prepare<'a> {
111112
.process_lines(&mut |line, _| {
112113
if line.contains("failed to select a version for the requirement") {
113114
yanked_deps = true;
115+
} else if line.contains("failed to load source for dependency")
116+
|| line.contains("no matching package named")
117+
{
118+
missing_deps = true;
114119
}
115120
})
116121
.run();
117122
match res {
118123
Err(_) if yanked_deps => {
119124
return Err(PrepareError::YankedDependencies.into());
120125
}
126+
Err(_) if missing_deps => {
127+
return Err(PrepareError::MissingDependencies.into());
128+
}
121129
other => other?,
122130
}
123131
self.lockfile_captured = true;
@@ -349,6 +357,9 @@ pub enum PrepareError {
349357
/// Some of this crate's dependencies were yanked, preventing Crater from fetching them.
350358
#[fail(display = "the crate depends on yanked dependencies")]
351359
YankedDependencies,
360+
/// Some of the dependencies do not exist anymore.
361+
#[fail(display = "the crate depends on missing dependencies")]
362+
MissingDependencies,
352363
}
353364

354365
#[cfg(test)]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "missing-deps"
3+
version = "0.1.0"
4+
authors = ["Pietro Albini <pietro@pietroalbini.org>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
not-a-git-repo = { git = "https://www.example.com/definitely-not-a-git-repo.git" }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "missing-deps-registry"
3+
version = "0.1.0"
4+
authors = ["Pietro Albini <pietro@pietroalbini.org>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
# The `macro` crate name is reserved on crates.io.
11+
macro = "*"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

tests/buildtest/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,15 @@ test_prepare_error!(
131131
);
132132

133133
test_prepare_error!(test_yanked_deps, "yanked-deps", YankedDependencies);
134+
135+
test_prepare_error!(
136+
test_missing_deps_git,
137+
"missing-deps-git",
138+
MissingDependencies
139+
);
140+
141+
test_prepare_error!(
142+
test_missing_deps_registry,
143+
"missing-deps-registry",
144+
MissingDependencies
145+
);

0 commit comments

Comments
 (0)