Skip to content

Commit 2ce8476

Browse files
fix failure errors in executable
1 parent 31b65db commit 2ce8476

File tree

7 files changed

+75
-73
lines changed

7 files changed

+75
-73
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

collector/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = '2018'
88
clap = "2.25"
99
env_logger = "0.7"
1010
anyhow = "1"
11+
thiserror = "1"
1112
log = "0.4"
1213
serde = { version = "1", features = ["derive"] }
1314
serde_json = "1"

collector/src/bin/rustc-perf-collector/background_worker.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::bail;
12
use collector::api::collected;
23
use crossbeam_channel::{unbounded, Receiver, Sender};
34
use log::warn;
@@ -10,7 +11,7 @@ lazy_static::lazy_static! {
1011
RwLock::new(Some(start_bg_thread()));
1112
}
1213

13-
fn call_home(client: &reqwest::Client, request: &collected::Request) -> Result<(), failure::Error> {
14+
fn call_home(client: &reqwest::Client, request: &collected::Request) -> anyhow::Result<()> {
1415
let resp = client
1516
.post(&format!(
1617
"{}/perf/collected",

collector/src/bin/rustc-perf-collector/execute.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ use tempfile::TempDir;
1111

1212
use collector::{command_output, BenchmarkState, Patch, Run, SelfProfile, StatId, Stats};
1313

14-
use failure::{err_msg, Error, ResultExt};
14+
use anyhow::{bail, Context};
1515

1616
use crate::{BuildKind, Compiler, RunKind};
1717

18-
fn touch_all(path: &Path) -> Result<(), Error> {
18+
fn touch_all(path: &Path) -> anyhow::Result<()> {
1919
let mut cmd = Command::new("bash");
2020
cmd.current_dir(path)
2121
.args(&["-c", "find . -name '*.rs' | xargs touch"]);
@@ -83,11 +83,11 @@ pub enum Profiler {
8383
Eprintln,
8484
}
8585

86-
#[derive(Fail, PartialEq, Eq, Debug)]
86+
#[derive(thiserror::Error, PartialEq, Eq, Debug)]
8787
pub enum FromNameError {
88-
#[fail(display = "'perf-stat' cannot be used as the profiler")]
88+
#[error("'perf-stat' cannot be used as the profiler")]
8989
PerfStat,
90-
#[fail(display = "'{:?}' is not a known profiler", _0)]
90+
#[error("'{:?}' is not a known profiler", .0)]
9191
UnknownProfiler(String),
9292
}
9393

@@ -196,7 +196,7 @@ impl<'a> CargoProcess<'a> {
196196
package_id.trim().to_string()
197197
}
198198

199-
fn run_rustc(&mut self) -> Result<(), Error> {
199+
fn run_rustc(&mut self) -> anyhow::Result<()> {
200200
loop {
201201
let mut cmd = self.base_command(self.cwd, "rustc");
202202
cmd.arg("-p").arg(self.get_pkgid(self.cwd));
@@ -284,7 +284,7 @@ pub trait Processor {
284284
&mut self,
285285
data: &ProcessOutputData<'_>,
286286
output: process::Output,
287-
) -> Result<Retry, Error>;
287+
) -> anyhow::Result<Retry>;
288288

289289
/// Provided to permit switching on more expensive profiling if it's needed
290290
/// for the "first" run for any given benchmark (we reuse the processor),
@@ -356,7 +356,7 @@ impl Processor for MeasureProcessor {
356356
&mut self,
357357
data: &ProcessOutputData<'_>,
358358
output: process::Output,
359-
) -> Result<Retry, Error> {
359+
) -> anyhow::Result<Retry> {
360360
match process_perf_stat_output(output) {
361361
Ok((stats, profile)) => {
362362
match data.run_kind {
@@ -480,7 +480,7 @@ impl<'a> Processor for ProfileProcessor<'a> {
480480
&mut self,
481481
data: &ProcessOutputData<'_>,
482482
output: process::Output,
483-
) -> Result<Retry, Error> {
483+
) -> anyhow::Result<Retry> {
484484
// Produce a name of the form $PREFIX-$ID-$BENCHMARK-$BUILDKIND-$RUNKIND.
485485
let out_file = |prefix: &str| -> String {
486486
format!(
@@ -640,7 +640,7 @@ impl<'a> Processor for ProfileProcessor<'a> {
640640
}
641641

642642
impl Benchmark {
643-
pub fn new(name: String, path: PathBuf) -> Result<Self, Error> {
643+
pub fn new(name: String, path: PathBuf) -> anyhow::Result<Self> {
644644
let mut patches = vec![];
645645
for entry in fs::read_dir(&path)? {
646646
let entry = entry?;
@@ -660,9 +660,9 @@ impl Benchmark {
660660
let config: BenchmarkConfig = if config_path.exists() {
661661
serde_json::from_reader(
662662
File::open(&config_path)
663-
.with_context(|_| format!("failed to open {:?}", config_path))?,
663+
.with_context(|| format!("failed to open {:?}", config_path))?,
664664
)
665-
.with_context(|_| format!("failed to parse {:?}", config_path))?
665+
.with_context(|| format!("failed to parse {:?}", config_path))?
666666
} else {
667667
BenchmarkConfig::default()
668668
};
@@ -679,15 +679,15 @@ impl Benchmark {
679679
self.config.supports_stable
680680
}
681681

682-
fn make_temp_dir(&self, base: &Path) -> Result<TempDir, Error> {
682+
fn make_temp_dir(&self, base: &Path) -> anyhow::Result<TempDir> {
683683
// Appending `.` means we copy just the contents of `base` into
684684
// `tmp_dir`, rather than `base` itself.
685685
let mut base_dot = base.to_path_buf();
686686
base_dot.push(".");
687687
let tmp_dir = TempDir::new()?;
688688
let mut cmd = Command::new("cp");
689689
cmd.arg("-R").arg(base_dot).arg(tmp_dir.path());
690-
command_output(&mut cmd).with_context(|_| format!("copying {} to tmp dir", self.name))?;
690+
command_output(&mut cmd).with_context(|| format!("copying {} to tmp dir", self.name))?;
691691
Ok(tmp_dir)
692692
}
693693

@@ -744,7 +744,7 @@ impl Benchmark {
744744
run_kinds: &[RunKind],
745745
compiler: Compiler<'_>,
746746
iterations: usize,
747-
) -> Result<Vec<Run>, Error> {
747+
) -> anyhow::Result<Vec<Run>> {
748748
let iterations = cmp::min(iterations, self.config.runs);
749749

750750
if self.config.disabled {
@@ -811,7 +811,7 @@ impl Benchmark {
811811
if run_kinds.contains(&RunKind::PatchedIncrs) {
812812
for (i, patch) in self.patches.iter().enumerate() {
813813
log::debug!("applying patch {}", patch.name);
814-
patch.apply(cwd).map_err(|s| err_msg(s))?;
814+
patch.apply(cwd).map_err(|s| anyhow::anyhow!("{}", s))?;
815815

816816
// An incremental build with some changes (realistic
817817
// incremental case).
@@ -836,15 +836,12 @@ impl Benchmark {
836836
}
837837
}
838838

839-
#[derive(Fail, PartialEq, Eq, Debug)]
839+
#[derive(thiserror::Error, PartialEq, Eq, Debug)]
840840
enum DeserializeStatError {
841-
#[fail(
842-
display = "could not deserialize empty output to stats, output: {:?}",
843-
_0
844-
)]
841+
#[error("could not deserialize empty output to stats, output: {:?}", .0)]
845842
NoOutput(process::Output),
846-
#[fail(display = "could not parse `{}` as a float", _0)]
847-
ParseError(String, #[fail(cause)] ::std::num::ParseFloatError),
843+
#[error("could not parse `{}` as a float", .0)]
844+
ParseError(String, #[source] ::std::num::ParseFloatError),
848845
}
849846

850847
fn process_perf_stat_output(

collector/src/bin/rustc-perf-collector/main.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
#![recursion_limit = "1024"]
22

3-
#[macro_use]
4-
extern crate failure;
53
#[macro_use]
64
extern crate clap;
75

6+
use anyhow::{bail, Context};
87
use chrono::{Timelike, Utc};
98
use collector::api::collected;
109
use collector::git::get_commit_or_fake_it;
1110
use collector::git::get_rust_commits as get_commits;
1211
use collector::{ArtifactData, Commit, CommitData, Date};
13-
use failure::{Error, ResultExt, SyncFailure};
1412
use log::{debug, error, info, warn};
1513
use std::collections::BTreeMap;
1614
use std::collections::HashSet;
@@ -82,9 +80,9 @@ impl RunKind {
8280
}
8381
}
8482

85-
#[derive(Fail, PartialEq, Eq, Debug)]
83+
#[derive(thiserror::Error, PartialEq, Eq, Debug)]
8684
pub enum KindError {
87-
#[fail(display = "'{:?}' is not a known {} kind", _1, _0)]
85+
#[error("'{:?}' is not a known {} kind", .1, .0)]
8886
UnknownKind(&'static str, String),
8987
}
9088

@@ -153,7 +151,7 @@ fn process_commits(
153151
out_repo: outrepo::Repo,
154152
benchmarks: &[Benchmark],
155153
collect_self_profile: bool,
156-
) -> Result<(), Error> {
154+
) -> anyhow::Result<()> {
157155
println!("processing commits");
158156
let client = reqwest::Client::new();
159157
let commit: Option<String> = client
@@ -200,18 +198,18 @@ fn bench_published(
200198
id: &str,
201199
repo: outrepo::Repo,
202200
mut benchmarks: Vec<Benchmark>,
203-
) -> Result<(), Error> {
201+
) -> anyhow::Result<()> {
204202
let commit = Commit {
205203
sha: String::from("<none>"),
206204
date: Date::ymd_hms(2010, 01, 01, 0, 0, 0),
207205
};
208-
let cfg = rustup::Cfg::from_env(Arc::new(|_| {})).map_err(SyncFailure::new)?;
206+
let cfg = rustup::Cfg::from_env(Arc::new(|_| {})).map_err(|e| anyhow::anyhow!("{:?}", e))?;
209207
let toolchain = rustup::Toolchain::from(&cfg, id)
210-
.map_err(SyncFailure::new)
211-
.with_context(|_| format!("creating toolchain for id: {}", id))?;
208+
.map_err(|e| anyhow::anyhow!("{:?}", e))
209+
.with_context(|| format!("creating toolchain for id: {}", id))?;
212210
toolchain
213211
.install_from_dist_if_not_installed()
214-
.map_err(SyncFailure::new)?;
212+
.map_err(|e| anyhow::anyhow!("{:?}", e))?;
215213

216214
// Remove benchmarks that don't work with a stable compiler.
217215
benchmarks.retain(|b| b.supports_stable());
@@ -337,7 +335,7 @@ fn get_benchmarks(
337335
benchmark_dir: &Path,
338336
filter: Option<&str>,
339337
exclude: Option<&str>,
340-
) -> Result<Vec<Benchmark>, Error> {
338+
) -> anyhow::Result<Vec<Benchmark>> {
341339
let mut benchmarks = Vec::new();
342340
'outer: for entry in fs::read_dir(benchmark_dir).context("failed to list benchmarks")? {
343341
let entry = entry?;
@@ -388,7 +386,7 @@ fn main() {
388386
}
389387
}
390388

391-
fn main_result() -> Result<i32, Error> {
389+
fn main_result() -> anyhow::Result<i32> {
392390
env_logger::init();
393391

394392
let matches = clap_app!(rustc_perf_collector =>

collector/src/bin/rustc-perf-collector/outrepo.rs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Write benchmark information to the output repository
22
3+
use anyhow::{anyhow, Context};
34
use collector::{ArtifactData, Commit, CommitData};
4-
use failure::{Error, ResultExt};
55
use log::{debug, info, trace, warn};
66
use std::fs;
77
use std::path::{Path, PathBuf};
@@ -16,15 +16,15 @@ pub struct Repo {
1616
}
1717

1818
impl Repo {
19-
fn git(&self, args: &[&str]) -> Result<(), Error> {
19+
fn git(&self, args: &[&str]) -> anyhow::Result<()> {
2020
for iteration in 0..5 {
2121
let mut command = Command::new("git");
2222
command.current_dir(&self.path);
2323
info!("[{}/5]: git {:?}", iteration, args);
2424
command.args(args);
2525
let mut child = command
2626
.spawn()
27-
.with_context(|_| format!("could not spawn git {:?}", args))?;
27+
.with_context(|| format!("could not spawn git {:?}", args))?;
2828
let start_time = Instant::now();
2929
loop {
3030
if start_time.elapsed().as_secs() > 30 {
@@ -38,41 +38,45 @@ impl Repo {
3838
if status.success() {
3939
return Ok(());
4040
} else {
41-
bail!(
41+
return Err(anyhow!(
4242
"command `git {:?}` failed in `{}`",
4343
args,
4444
self.path.display()
45-
);
45+
));
4646
}
4747
}
4848
Ok(None) => {
4949
debug!("waiting 250ms...");
5050
thread::sleep(time::Duration::from_millis(250));
5151
}
52-
Err(err) => bail!(
53-
"command `git {:?}` failed to try_wait in {:?}: {:?}",
54-
args,
55-
self.path.display(),
56-
err
57-
),
52+
Err(err) => {
53+
return Err(anyhow!(
54+
"command `git {:?}` failed to try_wait in {:?}: {:?}",
55+
args,
56+
self.path.display(),
57+
err
58+
))
59+
}
5860
}
5961
}
6062
}
61-
bail!("failed to run git command, timed out too many times")
63+
Err(anyhow!(
64+
"failed to run git command, timed out too many times"
65+
))
6266
}
6367

64-
pub fn open(path: PathBuf, allow_new_dir: bool, use_remote: bool) -> Result<Self, Error> {
68+
pub fn open(path: PathBuf, allow_new_dir: bool, use_remote: bool) -> anyhow::Result<Self> {
6569
let result = Repo {
6670
path: path,
6771
use_remote,
6872
};
6973

7074
// Don't nuke random repositories, unless specifically requested.
7175
if !allow_new_dir && !result.perf_file().exists() {
72-
bail!(
76+
return Err(anyhow!(
7377
"`{}` file not present, refusing to run",
7478
result.perf_file().display()
75-
);
79+
));
7680
}
7781

7882
if result.use_remote && result.path.join(".git").exists() {
@@ -85,13 +89,13 @@ impl Repo {
8589
Ok(result)
8690
}
8791

88-
pub fn success(&self, data: &CommitData) -> Result<(), Error> {
92+
pub fn success(&self, data: &CommitData) -> anyhow::Result<()> {
8993
self.add_commit_data(data)?;
9094
self.commit_and_push(&format!("{} - success", data.commit.sha))?;
9195
Ok(())
9296
}
9397

94-
pub fn success_artifact(&self, data: &ArtifactData) -> Result<(), Error> {
98+
pub fn success_artifact(&self, data: &ArtifactData) -> anyhow::Result<()> {
9599
let filepath = self.times().join(format!("artifact-{}.json", data.id));
96100
info!("creating file {}", filepath.display());
97101
let serialized = serde_json::to_string(&data)?;
@@ -100,7 +104,7 @@ impl Repo {
100104
Ok(())
101105
}
102106

103-
fn commit_and_push(&self, message: &str) -> Result<(), Error> {
107+
fn commit_and_push(&self, message: &str) -> anyhow::Result<()> {
104108
self.git(&["add", "times"])?;
105109

106110
// dirty index
@@ -115,16 +119,16 @@ impl Repo {
115119
Ok(())
116120
}
117121

118-
fn load_commit_data_file(&self, filepath: &Path) -> Result<CommitData, Error> {
122+
fn load_commit_data_file(&self, filepath: &Path) -> anyhow::Result<CommitData> {
119123
trace!("loading file {}", filepath.display());
120124
let contents =
121-
fs::read(&filepath).with_context(|_| format!("failed to read {:?}", filepath))?;
125+
fs::read(&filepath).with_context(|| format!("failed to read {:?}", filepath))?;
122126
let data = serde_json::from_slice(&contents)
123-
.with_context(|_| format!("failed to read JSON from {:?}", filepath))?;
127+
.with_context(|| format!("failed to read JSON from {:?}", filepath))?;
124128
Ok(data)
125129
}
126130

127-
pub fn load_commit_data(&self, commit: &Commit, triple: &str) -> Result<CommitData, Error> {
131+
pub fn load_commit_data(&self, commit: &Commit, triple: &str) -> anyhow::Result<CommitData> {
128132
let filepath = self.times().join(format!(
129133
"{}-{}-{}.json",
130134
commit.date.0.to_rfc3339(),
@@ -141,7 +145,7 @@ impl Repo {
141145
}
142146
}
143147

144-
pub fn add_commit_data(&self, data: &CommitData) -> Result<(), Error> {
148+
pub fn add_commit_data(&self, data: &CommitData) -> anyhow::Result<()> {
145149
let commit = &data.commit;
146150
let filepath = self
147151
.times()

0 commit comments

Comments
 (0)