Skip to content

Commit 392d979

Browse files
committed
detect manifest parse failure during deps fetch
to see if the dependencies manifest including dependencies is valid as well
1 parent 2ccfee3 commit 392d979

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

src/prepare.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl<'a> Prepare<'a> {
103103

104104
let mut yanked_deps = false;
105105
let mut missing_deps = false;
106+
let mut broken_deps = false;
106107
let mut cmd = Command::new(self.workspace, self.toolchain.cargo()).args(&[
107108
"generate-lockfile",
108109
"--manifest-path",
@@ -123,6 +124,8 @@ impl<'a> Prepare<'a> {
123124
|| line.contains("no matching package named")
124125
{
125126
missing_deps = true;
127+
} else if line.contains("failed to parse manifest at") {
128+
broken_deps = true;
126129
}
127130
})
128131
.run_capture()
@@ -134,6 +137,9 @@ impl<'a> Prepare<'a> {
134137
Err(CommandError::ExecutionFailed { status: _, stderr }) if missing_deps => {
135138
Err(PrepareError::MissingDependencies(stderr).into())
136139
}
140+
Err(CommandError::ExecutionFailed { status: _, stderr }) if broken_deps => {
141+
Err(PrepareError::InvalidCargoTomlSyntaxInDependencies(stderr).into())
142+
}
137143
Err(err) => Err(err.into()),
138144
}
139145
}
@@ -150,6 +156,7 @@ pub(crate) fn fetch_deps(
150156
fetch_build_std_targets: &[&str],
151157
) -> anyhow::Result<()> {
152158
let mut missing_deps = false;
159+
let mut broken_deps = false;
153160
let mut cmd = Command::new(workspace, toolchain.cargo())
154161
.args(&["fetch", "--manifest-path", "Cargo.toml"])
155162
.cd(source_dir);
@@ -168,13 +175,19 @@ pub(crate) fn fetch_deps(
168175
if line.contains("failed to load source for dependency") {
169176
missing_deps = true;
170177
}
178+
if line.contains("failed to parse manifest at") {
179+
broken_deps = true;
180+
}
171181
})
172182
.run_capture()
173183
{
174184
Ok(_) => Ok(()),
175185
Err(CommandError::ExecutionFailed { status: _, stderr }) if missing_deps => {
176186
Err(PrepareError::MissingDependencies(stderr).into())
177187
}
188+
Err(CommandError::ExecutionFailed { status: _, stderr }) if broken_deps => {
189+
Err(PrepareError::InvalidCargoTomlSyntaxInDependencies(stderr).into())
190+
}
178191
Err(err) => Err(err.into()),
179192
}
180193
}
@@ -384,6 +397,10 @@ pub enum PrepareError {
384397
/// rejecting it.
385398
#[error("invalid Cargo.toml syntax")]
386399
InvalidCargoTomlSyntax,
400+
/// A dependencies Cargo.toml is invalid, either due to a TOML syntax error in it or cargo
401+
/// rejecting it.
402+
#[error("invalid Cargo.toml syntax in dependencies:\n\n{0}")]
403+
InvalidCargoTomlSyntaxInDependencies(String),
387404
/// Some of this crate's dependencies were yanked, preventing Crater from fetching them.
388405
#[error("the crate depends on yanked dependencies: \n\n{0}")]
389406
YankedDependencies(String),
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "invalid-cargotoml-content-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+
parity-db = "=0.2.3"
11+
# invalid package name in invalid-cargotoml-content is too invalid
12+
# invalid-cargotoml-content = { git = "https://github.com/rust-lang/rustwide.git", rev = "ee102383cbe40aafdfce7bf04a120226c16a8983" }
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ test_prepare_error!(
188188
InvalidCargoTomlSyntax
189189
);
190190

191+
test_prepare_error_stderr!(
192+
test_invalid_cargotoml_content_deps,
193+
"invalid-cargotoml-content-deps",
194+
InvalidCargoTomlSyntaxInDependencies,
195+
"failed to parse the version requirement `0.11\t` for dependency `parking_lot`"
196+
);
197+
191198
test_prepare_error_stderr!(
192199
test_yanked_deps,
193200
"yanked-deps",

0 commit comments

Comments
 (0)