Skip to content

Commit 5ce9469

Browse files
committed
wip
1 parent bad405d commit 5ce9469

File tree

5 files changed

+72
-30
lines changed

5 files changed

+72
-30
lines changed

src/cmd/mod.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ pub enum CommandError {
7171
Timeout(u64),
7272

7373
/// The command failed to execute.
74-
#[error("command failed: {0}")]
75-
ExecutionFailed(ExitStatus),
74+
#[error("command failed: {status}\n\n{stderr}")]
75+
ExecutionFailed {
76+
/// the exit status we got from the command
77+
status: ExitStatus,
78+
/// the stderr output, if it was captured via `.run_capture()`
79+
stderr: String,
80+
},
7681

7782
/// Killing the underlying process after the timeout failed.
7883
#[error("{0}")]
@@ -496,7 +501,10 @@ impl<'w, 'pl> Command<'w, 'pl> {
496501
if out.status.success() {
497502
Ok(out.into())
498503
} else {
499-
Err(CommandError::ExecutionFailed(out.status))
504+
Err(CommandError::ExecutionFailed {
505+
status: out.status,
506+
stderr: out.stderr.join("\n"),
507+
})
500508
}
501509
}
502510
}

src/cmd/sandbox.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ impl Container<'_> {
393393
// Return a different error if the container was killed due to an OOM
394394
if details.state.oom_killed {
395395
Err(match res {
396-
Ok(_) | Err(CommandError::ExecutionFailed(_)) => CommandError::SandboxOOM,
396+
Ok(_) | Err(CommandError::ExecutionFailed { .. }) => CommandError::SandboxOOM,
397397
Err(err) => err,
398398
})
399399
} else {

src/prepare.rs

+23-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::cmd::Command;
1+
use crate::cmd::{Command, CommandError};
22
use crate::{build::CratePatch, Crate, Toolchain, Workspace};
33
use anyhow::Context as _;
44
use log::info;
@@ -113,7 +113,8 @@ impl<'a> Prepare<'a> {
113113
.args(&["-Zno-index-update"])
114114
.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly");
115115
}
116-
let res = cmd
116+
117+
match cmd
117118
.cd(self.source_dir)
118119
.process_lines(&mut |line, _| {
119120
if line.contains("failed to select a version for the requirement") {
@@ -124,17 +125,17 @@ impl<'a> Prepare<'a> {
124125
missing_deps = true;
125126
}
126127
})
127-
.run();
128-
match res {
129-
Err(_) if yanked_deps => {
130-
return Err(PrepareError::YankedDependencies.into());
128+
.run_capture()
129+
{
130+
Ok(_) => Ok(()),
131+
Err(CommandError::ExecutionFailed { status: _, stderr }) if yanked_deps => {
132+
Err(PrepareError::YankedDependencies(stderr).into())
131133
}
132-
Err(_) if missing_deps => {
133-
return Err(PrepareError::MissingDependencies.into());
134+
Err(CommandError::ExecutionFailed { status: _, stderr }) if missing_deps => {
135+
Err(PrepareError::MissingDependencies(stderr).into())
134136
}
135-
other => other?,
137+
Err(err) => Err(err.into()),
136138
}
137-
Ok(())
138139
}
139140

140141
fn fetch_deps(&mut self) -> anyhow::Result<()> {
@@ -161,17 +162,20 @@ pub(crate) fn fetch_deps(
161162
for target in fetch_build_std_targets {
162163
cmd = cmd.args(&["--target", target]);
163164
}
164-
let res = cmd
165+
166+
match cmd
165167
.process_lines(&mut |line, _| {
166168
if line.contains("failed to load source for dependency") {
167169
missing_deps = true;
168170
}
169171
})
170-
.run();
171-
match res {
172+
.run_capture()
173+
{
172174
Ok(_) => Ok(()),
173-
Err(_) if missing_deps => Err(PrepareError::MissingDependencies.into()),
174-
err => err.map_err(|e| e.into()),
175+
Err(CommandError::ExecutionFailed { status: _, stderr }) if missing_deps => {
176+
Err(PrepareError::MissingDependencies(stderr).into())
177+
}
178+
Err(err) => Err(err.into()),
175179
}
176180
}
177181

@@ -381,11 +385,11 @@ pub enum PrepareError {
381385
#[error("invalid Cargo.toml syntax")]
382386
InvalidCargoTomlSyntax,
383387
/// Some of this crate's dependencies were yanked, preventing Crater from fetching them.
384-
#[error("the crate depends on yanked dependencies")]
385-
YankedDependencies,
388+
#[error("the crate depends on yanked dependencies: \n\n{0}")]
389+
YankedDependencies(String),
386390
/// Some of the dependencies do not exist anymore.
387-
#[error("the crate depends on missing dependencies")]
388-
MissingDependencies,
391+
#[error("the crate depends on missing dependencies: \n\n{0}")]
392+
MissingDependencies(String),
389393
}
390394

391395
#[cfg(test)]

tests/buildtest/mod.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -188,22 +188,30 @@ test_prepare_error!(
188188
InvalidCargoTomlSyntax
189189
);
190190

191-
test_prepare_error!(test_yanked_deps, "yanked-deps", YankedDependencies);
191+
test_prepare_error_stderr!(
192+
test_yanked_deps,
193+
"yanked-deps",
194+
YankedDependencies,
195+
r#"failed to select a version for the requirement `ring = "^0.2"`"#
196+
);
192197

193-
test_prepare_error!(
198+
test_prepare_error_stderr!(
194199
test_missing_deps_git,
195200
"missing-deps-git",
196-
MissingDependencies
201+
MissingDependencies,
202+
"failed to get `not-a-git-repo` as a dependency of package `missing-deps v0.1.0"
197203
);
198204

199-
test_prepare_error!(
205+
test_prepare_error_stderr!(
200206
test_missing_deps_git_locked,
201207
"missing-deps-git-locked",
202-
MissingDependencies
208+
MissingDependencies,
209+
"failed to get `not-a-git-repo` as a dependency of package `missing-deps-git-locked v0.1.0"
203210
);
204211

205-
test_prepare_error!(
212+
test_prepare_error_stderr!(
206213
test_missing_deps_registry,
207214
"missing-deps-registry",
208-
MissingDependencies
215+
MissingDependencies,
216+
"error: no matching package named `macro` found"
209217
);

tests/buildtest/runner.rs

+22
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,25 @@ macro_rules! test_prepare_error {
8484
}
8585
};
8686
}
87+
88+
macro_rules! test_prepare_error_stderr {
89+
($name:ident, $krate:expr, $expected:ident, $expected_output:expr) => {
90+
#[test]
91+
fn $name() {
92+
runner::run($krate, |run| {
93+
let res = run.run(
94+
rustwide::cmd::SandboxBuilder::new().enable_networking(false),
95+
|_| Ok(()),
96+
);
97+
if let Some(rustwide::PrepareError::$expected(output)) =
98+
res.err().and_then(|err| err.downcast().ok())
99+
{
100+
assert!(output.contains($expected_output), "output: {:?}", output);
101+
} else {
102+
panic!("didn't get the error {}", stringify!($expected));
103+
}
104+
Ok(())
105+
});
106+
}
107+
};
108+
}

0 commit comments

Comments
 (0)