Skip to content

Commit bb3f2c5

Browse files
committed
Auto merge of #7776 - alexcrichton:anyhow, r=ehuss
Migrate from the `failure` crate to `anyhow` The `anyhow` crate interoperates with the `std::error::Error` trait rather than a custom `Fail` trait, and this is the general trend of error handling in Rust as well. Note that this is mostly mechanical (sed) and intended to get the test suite passing. As usual there's still more idiomatic cleanup that can happen, but that's left to later commits.
2 parents 7059559 + d0430dd commit bb3f2c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+429
-438
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ curl = { version = "0.4.23", features = ["http2"] }
2929
curl-sys = "0.4.22"
3030
env_logger = "0.7.0"
3131
pretty_env_logger = { version = "0.3", optional = true }
32-
failure = "0.1.5"
32+
anyhow = "1.0"
3333
filetime = "0.2"
3434
flate2 = { version = "1.0.3", features = ["zlib"] }
3535
fs2 = "0.4"
@@ -51,7 +51,7 @@ num_cpus = "1.0"
5151
opener = "0.4"
5252
percent-encoding = "2.0"
5353
remove_dir_all = "0.5.2"
54-
rustfix = "0.4.6"
54+
rustfix = "0.5.0"
5555
same-file = "1"
5656
semver = { version = "0.9.0", features = ["serde"] }
5757
serde = { version = "1.0.82", features = ["derive"] }

crates/cargo-test-support/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -916,11 +916,7 @@ impl Execs {
916916
{
917917
return self.match_output(out);
918918
}
919-
let mut s = format!("could not exec process {}: {}", process, e);
920-
for cause in e.iter_causes() {
921-
s.push_str(&format!("\ncaused by: {}", cause));
922-
}
923-
Err(s)
919+
Err(format!("could not exec process {}: {:?}", process, e))
924920
}
925921
}
926922
}

crates/crates-io/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ path = "lib.rs"
1515

1616
[dependencies]
1717
curl = "0.4"
18-
failure = "0.1.1"
18+
anyhow = "1.0.0"
1919
percent-encoding = "2.0"
2020
serde = { version = "1.0", features = ['derive'] }
2121
serde_derive = "1.0"

crates/crates-io/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ use std::io::prelude::*;
77
use std::io::Cursor;
88
use std::time::Instant;
99

10+
use anyhow::{bail, Result};
1011
use curl::easy::{Easy, List};
11-
use failure::bail;
1212
use percent_encoding::{percent_encode, NON_ALPHANUMERIC};
1313
use serde::{Deserialize, Serialize};
1414
use serde_json;
1515
use url::Url;
1616

17-
pub type Result<T> = std::result::Result<T, failure::Error>;
18-
1917
pub struct Registry {
2018
/// The base URL for issuing API requests.
2119
host: String,

src/bin/cargo/commands/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
100100
match err {
101101
None => Ok(()),
102102
Some(err) => Err(match err.exit.as_ref().and_then(|e| e.code()) {
103-
Some(i) => CliError::new(failure::format_err!("bench failed"), i),
103+
Some(i) => CliError::new(anyhow::format_err!("bench failed"), i),
104104
None => CliError::new(err.into(), 101),
105105
}),
106106
}

src/bin/cargo/commands/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
6060
Some("test") => true,
6161
None => false,
6262
Some(profile) => {
63-
let err = failure::format_err!(
63+
let err = anyhow::format_err!(
6464
"unknown profile: `{}`, only `test` is \
6565
currently supported",
6666
profile

src/bin/cargo/commands/clippy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
6666
args.compile_options(config, mode, Some(&ws), ProfileChecking::Checked)?;
6767

6868
if !config.cli_unstable().unstable_options {
69-
return Err(failure::format_err!(
69+
return Err(anyhow::format_err!(
7070
"`clippy-preview` is unstable, pass `-Z unstable-options` to enable it"
7171
)
7272
.into());

src/bin/cargo/commands/fix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
120120
Some("test") => true,
121121
None => false,
122122
Some(profile) => {
123-
let err = failure::format_err!(
123+
let err = anyhow::format_err!(
124124
"unknown profile: `{}`, only `test` is \
125125
currently supported",
126126
profile
@@ -143,7 +143,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
143143
.filter(|_| use_clippy);
144144

145145
if use_clippy && !config.cli_unstable().unstable_options {
146-
return Err(failure::format_err!(
146+
return Err(anyhow::format_err!(
147147
"`cargo fix --clippy` is unstable, pass `-Z unstable-options` to enable it"
148148
)
149149
.into());

src/bin/cargo/commands/locate_project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
2121
let root = root
2222
.to_str()
2323
.ok_or_else(|| {
24-
failure::format_err!(
24+
anyhow::format_err!(
2525
"your package path contains characters \
2626
not representable in Unicode"
2727
)

src/bin/cargo/commands/rustc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
5555
Some("bench") => CompileMode::Bench,
5656
Some("check") => CompileMode::Check { test: false },
5757
Some(mode) => {
58-
let err = failure::format_err!(
58+
let err = anyhow::format_err!(
5959
"unknown profile: `{}`, use dev,
6060
test, or bench",
6161
mode

0 commit comments

Comments
 (0)