Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Migrate from failure to anyhow #184

Merged
merged 4 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ exclude = [
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
failure = "0.1.2"
anyhow = "1.0.0"
log = "0.4.1"

[dev-dependencies]
Expand Down
4 changes: 1 addition & 3 deletions examples/fix-json.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use rustfix;

use failure::Error;
use anyhow::Error;
use std::io::{stdin, BufReader, Read};
use std::{collections::HashMap, collections::HashSet, env, fs};

Expand Down
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#[macro_use]
extern crate log;
#[macro_use]
extern crate failure;
#[cfg(test)]
#[macro_use]
extern crate proptest;
Expand All @@ -12,7 +10,7 @@ use serde_json;
use std::collections::HashSet;
use std::ops::Range;

use failure::Error;
use anyhow::Error;

pub mod diagnostics;
use crate::diagnostics::{Diagnostic, DiagnosticSpan};
Expand Down
4 changes: 2 additions & 2 deletions src/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! replacement of parts of its content, with the ability to prevent changing
//! the same parts multiple times.

use failure::Error;
use anyhow::{anyhow, ensure, Error};
use std::rc::Rc;

#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -133,7 +133,7 @@ impl Data {
);
}

format_err!(
anyhow!(
"Could not replace range {}...{} in file \
-- maybe parts of it were already replaced?",
from,
Expand Down
25 changes: 6 additions & 19 deletions tests/parse_and_replace.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
#![cfg(not(windows))] // TODO: should fix these tests on Windows

use duct;
use env_logger;
#[macro_use]
extern crate log;
use rustfix;

#[macro_use]
extern crate failure;

use anyhow::{anyhow, ensure, Context, Error};
use log::{debug, info, warn};
use rustfix::apply_suggestions;
use std::collections::HashSet;
use std::env;
use std::ffi::OsString;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Output;

use failure::{Error, ResultExt};
use tempdir::TempDir;

use rustfix::apply_suggestions;

mod fixmode {
pub const EVERYTHING: &str = "yolo";
pub const EDITION: &str = "edition";
Expand Down Expand Up @@ -67,7 +57,7 @@ fn compile_and_get_json_errors(file: &Path, mode: &str) -> Result<String, Error>

match res.status.code() {
Some(0) | Some(1) | Some(101) => Ok(stderr),
_ => Err(format_err!(
_ => Err(anyhow!(
"failed with status {:?}: {}",
res.status.code(),
stderr
Expand All @@ -86,7 +76,7 @@ fn compiles_without_errors(file: &Path, mode: &str) -> Result<(), Error> {
file,
String::from_utf8(res.stderr)?
);
Err(format_err!(
Err(anyhow!(
"failed with status {:?} (`env RUST_LOG=parse_and_replace=info` for more info)",
res.status.code(),
))
Expand Down Expand Up @@ -226,10 +216,7 @@ fn assert_fixtures(dir: &str, mode: &str) {
for file in &files {
if let Err(err) = test_rustfix_with_file(file, mode) {
println!("failed: {}", file.display());
warn!("{}", err);
for cause in err.iter_chain().skip(1) {
info!("\tcaused by: {}", cause);
}
warn!("{:?}", err);
failures += 1;
}
info!("passed: {:?}", file);
Expand Down