Skip to content

Commit 30b49bb

Browse files
committed
replace failure with anyhow
1 parent 77c7bfe commit 30b49bb

File tree

13 files changed

+31
-67
lines changed

13 files changed

+31
-67
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ aho-corasick = "0.7"
1010
atomicwrites = "0.4"
1111
bincode = "1.0"
1212
brotli = "3.3"
13-
failure = "0.1"
13+
anyhow = { version = "1.0", features = ["backtrace"]}
1414
futures = "0.3"
1515
fnv = "1.0"
1616
hex = "0.4"

src/bin/offline/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::rla;
2+
use anyhow::Context;
23
use brotli;
3-
use failure::ResultExt;
44
use percent_encoding::{AsciiSet, CONTROLS};
55
use std::fs;
66
use std::io::{Read, Write};
@@ -28,7 +28,7 @@ const FILENAME_ENCODE_SET: AsciiSet = CONTROLS
2828

2929
pub fn save_compressed(out: &Path, data: &[u8]) -> rla::Result<()> {
3030
let mut writer = brotli::CompressorWriter::new(
31-
fs::File::create(out).with_context(|_| format!("save_compressed: {:?}", out.to_owned()))?,
31+
fs::File::create(out).with_context(|| format!("save_compressed: {:?}", out.to_owned()))?,
3232
BROTLI_BUFFER,
3333
BROTLI_QUALITY,
3434
BROTLI_LGWIN,

src/bin/rla-offline.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
extern crate brotli;
99
#[macro_use]
10-
extern crate failure;
11-
#[macro_use]
1210
extern crate tracing;
1311
extern crate rust_log_analyzer as rla;
1412
extern crate walkdir;

src/bin/rla-server.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
clippy::useless_let_if_seq
66
)]
77

8-
#[macro_use]
9-
extern crate failure;
108
extern crate futures;
119
extern crate hyper;
1210
#[macro_use]

src/bin/server/service.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::{QueueItem, QueueItemKind};
22

33
use crate::rla;
4+
use anyhow::bail;
45
use hyper::{self, Body, Method, StatusCode};
56
use hyper::{Request, Response};
67
use serde_json;

src/bin/server/worker.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::{QueueItem, QueueItemKind};
22

33
use crate::rla;
44
use crate::rla::ci::{self, BuildCommit, CiPlatform};
5+
use anyhow::bail;
56
use std::collections::{HashSet, VecDeque};
67
use std::hash::Hash;
78
use std::path::PathBuf;
@@ -228,7 +229,7 @@ impl Worker {
228229
let s = &commit_message[BORS_MERGE_PREFIX.len()..];
229230
(
230231
s[..s.find(' ').ok_or_else(|| {
231-
format_err!("Invalid bors commit message: '{}'", commit_message)
232+
anyhow::format_err!("Invalid bors commit message: '{}'", commit_message)
232233
})?]
233234
.parse()?,
234235
true,

src/bin/util/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::rla;
2-
use failure::ResultExt;
2+
use anyhow::Context;
33
use std::process;
44

55
#[derive(Debug, Copy, Clone)]
@@ -13,26 +13,26 @@ impl CliCiPlatform {
1313
Ok(match self {
1414
CliCiPlatform::Azure => {
1515
let token = std::env::var("AZURE_DEVOPS_TOKEN")
16-
.with_context(|_| "failed to read AZURE_DEVOPS_TOKEN env var")?;
16+
.with_context(|| "failed to read AZURE_DEVOPS_TOKEN env var")?;
1717
Box::new(rla::ci::AzurePipelines::new(&token))
1818
}
1919
CliCiPlatform::Actions => {
2020
let token = std::env::var("GITHUB_TOKEN")
21-
.with_context(|_| "failed to read GITHUB_TOKEN env var")?;
21+
.with_context(|| "failed to read GITHUB_TOKEN env var")?;
2222
Box::new(rla::ci::GitHubActions::new(&token))
2323
}
2424
})
2525
}
2626
}
2727

2828
impl std::str::FromStr for CliCiPlatform {
29-
type Err = failure::Error;
29+
type Err = anyhow::Error;
3030

3131
fn from_str(input: &str) -> rla::Result<Self> {
3232
Ok(match input {
3333
"azure" => CliCiPlatform::Azure,
3434
"actions" => CliCiPlatform::Actions,
35-
other => bail!("unknown CI platform: {}", other),
35+
other => anyhow::bail!("unknown CI platform: {}", other),
3636
})
3737
}
3838
}

src/ci/actions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ fn fetch_workflow_run_id_from_check_run(
303303
}
304304
}
305305

306-
bail!("can't find the Workflow Run ID from the Check Run");
306+
anyhow::bail!("can't find the Workflow Run ID from the Check Run");
307307
}
308308

309309
#[derive(Debug, Eq, PartialEq, Hash)]
@@ -332,7 +332,7 @@ fn parse_link_header(content: &str) -> Result<HashMap<LinkRel, String>> {
332332
};
333333
result.insert(rel, captures[1].into());
334334
} else {
335-
failure::bail!("invalid link header entry: {}", entry);
335+
anyhow::bail!("invalid link header entry: {}", entry);
336336
}
337337
}
338338
Ok(result)

src/ci/azure.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(unused)]
22
use crate::ci::{Build, BuildCommit, CiPlatform, Job, Outcome};
33
use crate::Result;
4-
use failure::ResultExt;
4+
use anyhow::Context;
55
use reqwest::blocking::{Client as ReqwestClient, Response};
66
use reqwest::{Method, StatusCode};
77
use std::borrow::Cow;
@@ -185,7 +185,7 @@ impl AzureBuild {
185185
return Ok(None);
186186
}
187187
let dbg = format!("{:?}", resp);
188-
let timeline: Timeline = resp.json().with_context(|_| dbg)?;
188+
let timeline: Timeline = resp.json().with_context(|| dbg)?;
189189
Ok(Some(AzureBuild {
190190
jobs: timeline
191191
.records
@@ -354,7 +354,7 @@ impl CiPlatform for Client {
354354
if let Some(build) = AzureBuild::new(&self, repo, data)? {
355355
Ok(Box::new(build))
356356
} else {
357-
Err(failure::err_msg("no build results"))
357+
Err(anyhow::anyhow!("no build results"))
358358
}
359359
}
360360

0 commit comments

Comments
 (0)