Skip to content

Commit 31b65db

Browse files
Move off direct failure usage
1 parent 363e746 commit 31b65db

File tree

9 files changed

+57
-30
lines changed

9 files changed

+57
-30
lines changed

Cargo.lock

Lines changed: 29 additions & 2 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = '2018'
77
[dependencies]
88
clap = "2.25"
99
env_logger = "0.7"
10-
failure = "0.1.6"
10+
anyhow = "1"
1111
log = "0.4"
1212
serde = { version = "1", features = ["derive"] }
1313
serde_json = "1"

collector/src/git.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
time::{Duration, SystemTime},
77
};
88

9-
pub fn get_commit_or_fake_it(sha: &str) -> Result<Commit, failure::Error> {
9+
pub fn get_commit_or_fake_it(sha: &str) -> anyhow::Result<Commit> {
1010
Ok(get_rust_commits()?
1111
.iter()
1212
.find(|c| c.sha == sha)
@@ -21,7 +21,7 @@ pub fn get_commit_or_fake_it(sha: &str) -> Result<Commit, failure::Error> {
2121
}
2222

2323
/// This retrieves the list of Rust commits which may be available in the CI S3 bucket.
24-
pub fn get_rust_commits() -> Result<Vec<Commit>, failure::Error> {
24+
pub fn get_rust_commits() -> anyhow::Result<Vec<Commit>> {
2525
let repo_dir =
2626
PathBuf::from(env::var("RUST_SRC_REPO").unwrap_or_else(|_| String::from("rust.git")));
2727

collector/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -642,25 +642,25 @@ pub mod round_float {
642642
}
643643
}
644644

645-
pub fn run_command(cmd: &mut Command) -> Result<(), failure::Error> {
645+
pub fn run_command(cmd: &mut Command) -> anyhow::Result<()> {
646646
log::trace!("running: {:?}", cmd);
647647
let status = cmd.status()?;
648648
if !status.success() {
649-
failure::bail!("expected success {:?}", status);
649+
return Err(anyhow::anyhow!("expected success {:?}", status));
650650
}
651651
Ok(())
652652
}
653653

654-
pub fn command_output(cmd: &mut Command) -> Result<process::Output, failure::Error> {
654+
pub fn command_output(cmd: &mut Command) -> anyhow::Result<process::Output> {
655655
log::trace!("running: {:?}", cmd);
656656
let output = cmd.output()?;
657657
if !output.status.success() {
658-
failure::bail!(
658+
return Err(anyhow::anyhow!(
659659
"expected success, got {}\n\nstderr={}\n\n stdout={}",
660660
output.status,
661661
String::from_utf8_lossy(&output.stderr),
662662
String::from_utf8_lossy(&output.stdout)
663-
);
663+
));
664664
}
665665
Ok(output)
666666
}

site/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ edition = '2018'
66

77
[dependencies]
88
env_logger = "0.7"
9-
failure = "0.1"
9+
anyhow = "1"
10+
thiserror = "1"
1011
futures-preview = { version = "0.3.0-alpha.19", features = ["compat"] }
1112
log = "0.4"
1213
serde = "1"

site/src/git.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@ use std::path::Path;
1111
use std::process::Command;
1212

1313
use crate::CommandFailed;
14-
use failure::Error;
1514

1615
const BRANCH: &'static str = "master";
1716
const GIT: &'static str = "git";
1817
const GIT_CHECKOUT: &'static str = "checkout";
1918
const GIT_PULL: &'static str = "pull";
2019

21-
pub fn update_repo(repo_path: &str) -> Result<(), Error> {
20+
pub fn update_repo(repo_path: &str) -> anyhow::Result<()> {
2221
let working_dir = Path::new(repo_path);
2322
checkout_master(working_dir)?;
2423
pull_updates(working_dir)?;
2524
Ok(())
2625
}
2726

28-
pub fn execute_command(working_dir: &Path, args: &[&str]) -> Result<(), Error> {
27+
pub fn execute_command(working_dir: &Path, args: &[&str]) -> anyhow::Result<()> {
2928
let status = Command::new(GIT)
3029
.current_dir(working_dir)
3130
.args(args)
@@ -39,10 +38,10 @@ pub fn execute_command(working_dir: &Path, args: &[&str]) -> Result<(), Error> {
3938
}
4039
}
4140

42-
fn checkout_master(working_dir: &Path) -> Result<(), Error> {
41+
fn checkout_master(working_dir: &Path) -> anyhow::Result<()> {
4342
execute_command(working_dir, &[GIT_CHECKOUT, BRANCH])
4443
}
4544

46-
fn pull_updates(working_dir: &Path) -> Result<(), Error> {
45+
fn pull_updates(working_dir: &Path) -> anyhow::Result<()> {
4746
execute_command(working_dir, &[GIT_PULL])
4847
}

site/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
#[macro_use]
11-
extern crate failure;
10+
use thiserror::Error;
1211

13-
#[derive(Fail, Debug)]
14-
#[fail(display = "command failed: {}", command)]
12+
#[derive(Error, Debug)]
13+
#[error("command failed: {command}")]
1514
pub struct CommandFailed {
1615
command: String,
1716
}

site/src/load.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use std::env;
1212
use std::fs;
1313
use std::path::{Path, PathBuf};
1414

15+
use anyhow::Context;
1516
use chrono::{Duration, Utc};
16-
use failure::{Error, ResultExt};
1717
use parking_lot::Mutex;
1818
use serde::{Deserialize, Serialize};
1919

@@ -110,13 +110,13 @@ lazy_static::lazy_static! {
110110
}
111111

112112
impl Persistent {
113-
pub fn write(&self) -> Result<(), Error> {
113+
pub fn write(&self) -> anyhow::Result<()> {
114114
if PERSISTENT_PATH.exists() {
115115
let _ = fs::copy(&*PERSISTENT_PATH, "persistent.json.previous");
116116
}
117117
let s = serde_json::to_string(self)?;
118118
fs::write(&*PERSISTENT_PATH, &s)
119-
.with_context(|_| format!("failed to write persistent DB"))?;
119+
.with_context(|| format!("failed to write persistent DB"))?;
120120
Ok(())
121121
}
122122

@@ -189,7 +189,7 @@ impl InputData {
189189
}
190190

191191
/// Initialize `InputData from the file system.
192-
pub fn from_fs(repo_loc: &str) -> Result<InputData, Error> {
192+
pub fn from_fs(repo_loc: &str) -> anyhow::Result<InputData> {
193193
let repo_loc = PathBuf::from(repo_loc);
194194
let mut skipped = 0;
195195
let mut artifact_data = BTreeMap::new();
@@ -225,7 +225,7 @@ impl InputData {
225225
let filename = entry.file_name();
226226
let filename = filename.to_str().unwrap();
227227
let file_contents =
228-
fs::read(entry.path()).with_context(|_| format!("Failed to read {}", filename))?;
228+
fs::read(entry.path()).with_context(|| format!("Failed to read {}", filename))?;
229229

230230
if filename.starts_with("artifact-") {
231231
let contents: ArtifactData = match serde_json::from_slice(&file_contents) {
@@ -282,7 +282,7 @@ impl InputData {
282282
data: BTreeMap<Commit, CommitData>,
283283
artifact_data: BTreeMap<String, ArtifactData>,
284284
config: Config,
285-
) -> Result<InputData, Error> {
285+
) -> anyhow::Result<InputData> {
286286
let data = data.into_iter().map(|(_, v)| v).collect::<Vec<_>>();
287287
let mut last_date = None;
288288
let mut stats_list = BTreeSet::new();
@@ -514,7 +514,7 @@ impl InputData {
514514
})
515515
}
516516

517-
pub fn missing_commits(&self) -> Result<Vec<(Commit, MissingReason)>, Error> {
517+
pub fn missing_commits(&self) -> anyhow::Result<Vec<(Commit, MissingReason)>> {
518518
let known_benchmarks = self
519519
.data
520520
.iter()

site/src/util.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::env;
1111

1212
use crate::load::{CommitData, InputData};
1313
use collector::Bound;
14-
use failure::Error;
1514

1615
use chrono::Duration;
1716

@@ -96,11 +95,13 @@ pub fn data_range<'a>(
9695
}
9796

9897
/// Reads the repository path from the arguments passed to main()
99-
pub fn get_repo_path() -> Result<String, Error> {
98+
pub fn get_repo_path() -> anyhow::Result<String> {
10099
if let Some(p) = env::args().nth(1) {
101100
Ok(p)
102101
} else {
103-
bail!("No argument supplied, needs location of data repo.")
102+
return Err(anyhow::anyhow!(
103+
"No argument supplied, needs location of data repo."
104+
));
104105
}
105106
}
106107

0 commit comments

Comments
 (0)