Skip to content

Commit 00502c7

Browse files
Better error messages for summarize errors
1 parent 633b69c commit 00502c7

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

collector/src/rustc-fake.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::Context;
12
use std::env;
23
use std::ffi::OsString;
34
use std::fs;
@@ -113,7 +114,7 @@ fn main() {
113114
let filename = profile_data.file_name().unwrap().to_str().unwrap();
114115
let json = run_summarize("summarize", &prof_out_dir, filename)
115116
.or_else(|_| run_summarize("summarize-9.0", &prof_out_dir, filename))
116-
.expect("able to run summarize or summarize-0.7");
117+
.expect("able to run summarize or summarize-9.0");
117118
println!("!self-profile-output:{}", json);
118119
} else {
119120
let prefix = prefix.expect(&format!("found prefix {:?}", prof_out_dir));
@@ -343,19 +344,22 @@ fn print_time(dur: Duration) {
343344
);
344345
}
345346

346-
fn run_summarize(name: &str, prof_out_dir: &Path, prefix: &str) -> std::io::Result<String> {
347+
fn run_summarize(name: &str, prof_out_dir: &Path, prefix: &str) -> anyhow::Result<String> {
347348
let mut cmd = Command::new(name);
348349
cmd.current_dir(&prof_out_dir);
349350
cmd.arg("summarize").arg("--json");
350351
cmd.arg(&prefix);
351352
let status = cmd.status()?;
352353
if !status.success() {
353-
return Err(std::io::Error::new(
354-
std::io::ErrorKind::Other,
355-
"Failed to run successfully",
356-
));
354+
anyhow::bail!(
355+
"failed to run {} in {:?} with prefix {:?}",
356+
name,
357+
prof_out_dir,
358+
prefix
359+
)
357360
}
358-
fs::read_to_string(prof_out_dir.join(&format!("{}.json", prefix)))
361+
let json = prof_out_dir.join(&format!("{}.json", prefix));
362+
fs::read_to_string(&json).with_context(|| format!("failed to read {:?}", json))
359363
}
360364

361365
#[cfg(windows)]

0 commit comments

Comments
 (0)