Skip to content

Commit 4101cd0

Browse files
committed
update rustwide and switch from failure to anyhow
-switching as rustwide switched to anyhow
1 parent 7310a51 commit 4101cd0

37 files changed

+225
-367
lines changed

Cargo.lock

Lines changed: 114 additions & 175 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ opt-level = 0
1212
strip = false
1313

1414
[dependencies]
15+
anyhow = "1.0.95"
1516
aws-config = { version = "1", features = ["behavior-version-latest"] }
1617
aws-sdk-s3 = "1.7"
1718
base64 = "0.21.5"
@@ -26,7 +27,6 @@ ctrlc = "3.1.3"
2627
docsrs-metadata = { git = "https://github.com/rust-lang/docs.rs/" }
2728
dotenv = "0.15"
2829
env_logger = "0.10.0"
29-
failure = "0.1.3"
3030
flate2 = "1"
3131
hmac = "0.12"
3232
http = "0.2"
@@ -46,7 +46,7 @@ remove_dir_all = "0.7"
4646
reqwest = { version = "0.11", features = ["blocking", "json"] }
4747
rusqlite = { version = "0.32.1", features = ["chrono", "functions", "bundled"] }
4848
rust_team_data = { git = "https://github.com/rust-lang/team" }
49-
rustwide = { version = "0.16.0", features = ["unstable", "unstable-toolchain-ci"] }
49+
rustwide = { version = "0.19.0", features = ["unstable", "unstable-toolchain-ci"] }
5050
serde = "1.0"
5151
serde_derive = "1.0"
5252
serde_json = "1.0"

src/agent/api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl ResponseExt for ::reqwest::blocking::Response {
5252
let status = self.status();
5353
let result: ApiResponse<T> = self
5454
.json()
55-
.with_context(|_| format!("failed to parse API response (status code {status})",))?;
55+
.with_context(|| format!("failed to parse API response (status code {status})",))?;
5656
match result {
5757
ApiResponse::Success { result } => Ok(result),
5858
ApiResponse::SlowDown => Err(AgentApiError::ServerUnavailable.into()),
@@ -139,7 +139,7 @@ impl AgentApi {
139139
})
140140
}
141141

142-
pub fn next_experiment(&self) -> Fallible<Experiment> {
142+
pub fn next_experiment(&self) -> Result<Experiment> {
143143
self.retry(|this| loop {
144144
let resp: Option<_> = this
145145
.build_request(Method::POST, "next-experiment")

src/agent/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::experiments::Experiment;
88
use crate::prelude::*;
99
use crate::utils;
1010
use crate::utils::disk_usage::DiskUsage;
11-
use failure::Error;
11+
use anyhow::{Error, Result};
1212
use rustwide::Workspace;
1313
use std::collections::BTreeSet;
1414
use std::ops;
@@ -87,7 +87,7 @@ impl Agent {
8787
})
8888
}
8989

90-
fn experiment(&self) -> Fallible<Experiment> {
90+
fn experiment(&self) -> Result<Experiment> {
9191
info!("asking the server for a new experiment...");
9292
Ok(self.api.next_experiment()?)
9393
}
@@ -137,7 +137,7 @@ fn run_heartbeat(url: &str, token: &str) {
137137
let api = AgentApi::new(url, token);
138138

139139
thread::spawn(move || loop {
140-
if let Err(e) = api.heartbeat().with_context(|_| "failed to send heartbeat") {
140+
if let Err(e) = api.heartbeat().with_context(|| "failed to send heartbeat") {
141141
utils::report_failure(&e);
142142
}
143143
thread::sleep(Duration::from_secs(60));
@@ -203,8 +203,8 @@ pub fn run(
203203
if let Some(ex) = ex {
204204
if let Err(e) = agent
205205
.api
206-
.report_error(&ex, format!("{}", err.find_root_cause()))
207-
.with_context(|_| "error encountered")
206+
.report_error(&ex, format!("{}", err.root_cause()))
207+
.with_context(|| "error encountered")
208208
{
209209
utils::report_failure(&e);
210210
}

src/assets.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl FileContent {
9494
Ok(match *self {
9595
FileContent::Static(content) => Cow::Borrowed(content),
9696
FileContent::Dynamic(ref path) => {
97-
Cow::Owned(::std::fs::read(path).with_context(|_| {
97+
Cow::Owned(::std::fs::read(path).with_context(|| {
9898
format!("failed to load dynamic asset: {}", path.to_string_lossy())
9999
})?)
100100
}
@@ -140,7 +140,8 @@ fn build_tera_cache() -> Fallible<Tera> {
140140
.collect::<Vec<_>>();
141141

142142
let mut tera = Tera::default();
143-
tera.add_raw_templates(to_add).to_failure()?;
143+
tera.add_raw_templates(to_add)
144+
.map_err(|err| anyhow!("{err}"))?;
144145
Ok(tera)
145146
}
146147

@@ -164,5 +165,5 @@ pub fn render_template<C: Serialize>(name: &str, context: C) -> Fallible<String>
164165
let tera_context = tera::Context::from_serialize(context)?;
165166
Ok(tera
166167
.render(name, &tera_context)
167-
.map_err(|e| failure::format_err!("{:?}", e))?)
168+
.map_err(|e| anyhow!("{:?}", e))?)
168169
}

src/bin/test-report.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use anyhow::Result;
12
use crater::experiments::ExperimentDBRecord;
23
use crater::report::ReportWriter;
34
use crater::results::EncodingType;
45
use crater::{config::Config, db::QueryUtils};
5-
use failure::Fallible;
66
use mime::{self, Mime};
77
use std::{borrow::Cow, fmt, path::Path};
88

@@ -31,7 +31,7 @@ fn main() {
3131
let experiments: Vec<_> = experiments
3232
.into_iter()
3333
.map(|record| record.into_experiment())
34-
.collect::<Fallible<_>>()
34+
.collect::<Result<_>>()
3535
.unwrap();
3636
let ex = experiments.iter().find(|e| e.name == "pr-118920").unwrap();
3737
let rdb = crater::results::DatabaseDB::new(&db);
@@ -67,11 +67,11 @@ impl ReportWriter for NullWriter {
6767
_b: &[u8],
6868
_mime: &Mime,
6969
_encoding_type: EncodingType,
70-
) -> Fallible<()> {
70+
) -> Result<()> {
7171
// no-op
7272
Ok(())
7373
}
74-
fn write_string<P: AsRef<Path>>(&self, _path: P, _s: Cow<str>, _mime: &Mime) -> Fallible<()> {
74+
fn write_string<P: AsRef<Path>>(&self, _path: P, _s: Cow<str>, _mime: &Mime) -> Result<()> {
7575
// no-op
7676
Ok(())
7777
}

src/cli.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//! application state employs ownership techniques to ensure that
1010
//! parallel access is consistent and race-free.
1111
12+
use anyhow::{bail, Error, Result};
1213
use clap::Parser;
1314
use crater::actions::{self, Action, ActionsCtx};
1415
use crater::agent::{self, Capabilities};
@@ -21,7 +22,6 @@ use crater::results::{DatabaseDB, DeleteResults};
2122
use crater::runner;
2223
use crater::server;
2324
use crater::toolchain::Toolchain;
24-
use failure::{bail, Error, Fallible};
2525
use rustwide::{cmd::SandboxImage, Workspace, WorkspaceBuilder};
2626
use std::collections::HashSet;
2727
use std::net::SocketAddr;
@@ -38,15 +38,15 @@ pub struct DockerEnv(#[allow(unused)] String);
3838
impl FromStr for Ex {
3939
type Err = Error;
4040

41-
fn from_str(ex: &str) -> Fallible<Ex> {
41+
fn from_str(ex: &str) -> Result<Ex> {
4242
Ok(Ex(ex.to_string()))
4343
}
4444
}
4545

4646
impl FromStr for DockerEnv {
4747
type Err = Error;
4848

49-
fn from_str(env: &str) -> Fallible<DockerEnv> {
49+
fn from_str(env: &str) -> Result<DockerEnv> {
5050
Ok(DockerEnv(env.to_string()))
5151
}
5252
}
@@ -57,7 +57,7 @@ pub struct Dest(PathBuf);
5757
impl FromStr for Dest {
5858
type Err = Error;
5959

60-
fn from_str(env: &str) -> Fallible<Dest> {
60+
fn from_str(env: &str) -> Result<Dest> {
6161
Ok(Dest(env.into()))
6262
}
6363
}
@@ -273,7 +273,7 @@ pub enum Crater {
273273
}
274274

275275
impl Crater {
276-
pub fn run(&self) -> Fallible<()> {
276+
pub fn run(&self) -> Result<()> {
277277
match *self {
278278
Crater::CreateLists { ref lists } => {
279279
let mut lists: HashSet<_> = lists.iter().map(|s| s.as_str()).collect();

src/crates/lists.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) trait List {
2929
"INSERT INTO crates (crate, list, loaded_at) VALUES (?1, ?2, ?3);",
3030
&[&krate.id(), &Self::NAME, &now],
3131
)
32-
.with_context(|_| {
32+
.with_context(|| {
3333
format!(
3434
"failed to insert crate {} into the {} list",
3535
krate,

src/crates/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl Crate {
7171
}
7272

7373
impl TryFrom<&'_ PackageId> for Crate {
74-
type Error = failure::Error;
74+
type Error = anyhow::Error;
7575

7676
fn try_from(pkgid: &PackageId) -> Fallible<Crate> {
7777
let parts = &pkgid
@@ -153,7 +153,7 @@ impl fmt::Display for Crate {
153153
}
154154

155155
impl FromStr for Crate {
156-
type Err = ::failure::Error;
156+
type Err = ::anyhow::Error;
157157

158158
// matches with `Crate::id'
159159
fn from_str(s: &str) -> Fallible<Self> {

src/crates/sources/github.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl List for GitHubList {
3434
info!("loading cached GitHub list from {}", self.source);
3535

3636
let mut resp = crate::utils::http::get_sync(&self.source)
37-
.with_context(|_| format!("failed to fetch GitHub crates list from {}", self.source))?;
37+
.with_context(|| format!("failed to fetch GitHub crates list from {}", self.source))?;
3838
let mut reader = ::csv::Reader::from_reader(&mut resp);
3939

4040
let mut list = Vec::new();
@@ -88,7 +88,7 @@ impl GitHubRepo {
8888
}
8989

9090
impl FromStr for GitHubRepo {
91-
type Err = ::failure::Error;
91+
type Err = ::anyhow::Error;
9292

9393
fn from_str(input: &str) -> Fallible<Self> {
9494
let mut components = input

0 commit comments

Comments
 (0)