1409: The Fall down of failures r=matklad a=mominul

😁
Replaced all the uses of `failure` crate with `std::error::Error`.

Closes #1400 
Depends on rust-analyzer/teraron#1

Co-authored-by: Muhammad Mominul Huque <mominul2082@gmail.com>
This commit is contained in:
bors[bot] 2019-06-16 19:58:33 +00:00
commit 1541b2d689
5 changed files with 19 additions and 24 deletions

8
Cargo.lock generated
View file

@ -1227,9 +1227,8 @@ name = "ra_tools"
version = "0.1.0"
dependencies = [
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"teraron 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"teraron 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1684,10 +1683,9 @@ dependencies = [
[[package]]
name = "teraron"
version = "0.0.1"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ron 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tera 0.11.20 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2145,7 +2143,7 @@ dependencies = [
"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f"
"checksum tempfile 3.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7dc4738f2e68ed2855de5ac9cdbe05c9216773ecde4739b2f095002ab03a13ef"
"checksum tera 0.11.20 (registry+https://github.com/rust-lang/crates.io-index)" = "4b505279e19d8f7d24b1a9dc58327c9c36174b1a2c7ebdeac70792d017cb64f3"
"checksum teraron 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d89ad4617d1dec55331067fadaa041e813479e1779616f3d3ce9308bf46184e"
"checksum teraron 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9a447d012fef5c222f4b11a98fcef2a7e347a57f28be9957c5c390ac9a0e41e0"
"checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea"
"checksum termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625"
"checksum text_unit 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e08bbcb7a3adbda0eb23431206b653bdad3d8dea311e72d36bf2215e27a42579"

View file

@ -6,8 +6,7 @@ authors = ["rust-analyzer developers"]
publish = false
[dependencies]
teraron = "0.0.1"
teraron = "0.1.0"
walkdir = "2.1.3"
itertools = "0.8.0"
clap = "2.32.0"
failure = "0.1.4"

View file

@ -1,7 +1,5 @@
use std::process::Command;
use failure::bail;
use ra_tools::{Result, run_rustfmt, run, project_root, Overwrite};
fn main() -> Result<()> {
@ -19,7 +17,10 @@ fn update_staged() -> Result<()> {
.current_dir(&root)
.output()?;
if !output.status.success() {
bail!("`git diff --diff-filter=MAR --name-only --cached` exited with {}", output.status);
Err(format!(
"`git diff --diff-filter=MAR --name-only --cached` exited with {}",
output.status
))?;
}
for line in String::from_utf8(output.stdout)?.lines() {
run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?;

View file

@ -3,15 +3,15 @@ use std::{
collections::HashMap,
path::{Path, PathBuf},
process::{Command, Output, Stdio},
io::{Error, ErrorKind}
io::{Error as IoError, ErrorKind},
error::Error
};
use failure::bail;
use itertools::Itertools;
pub use teraron::{Mode, Overwrite, Verify};
pub type Result<T> = std::result::Result<T, failure::Error>;
pub type Result<T> = std::result::Result<T, Box<dyn Error>>;
pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron";
const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar";
@ -128,7 +128,7 @@ pub fn install_format_hook() -> Result<()> {
fs::copy("./target/debug/pre-commit", result_path)?;
}
} else {
return Err(Error::new(ErrorKind::AlreadyExists, "Git hook already created").into());
Err(IoError::new(ErrorKind::AlreadyExists, "Git hook already created"))?;
}
Ok(())
}
@ -224,7 +224,7 @@ where
f(cmd.args(args).current_dir(proj_dir).stderr(Stdio::inherit()));
let output = cmd.output()?;
if !output.status.success() {
bail!("`{}` exited with {}", cmdline, output.status);
Err(format!("`{}` exited with {}", cmdline, output.status))?;
}
Ok(output)
}
@ -256,11 +256,11 @@ fn tests_from_dir(dir: &Path) -> Result<Tests> {
for (_, test) in collect_tests(&text) {
if test.ok {
if let Some(old_test) = res.ok.insert(test.name.clone(), test) {
bail!("Duplicate test: {}", old_test.name)
Err(format!("Duplicate test: {}", old_test.name))?
}
} else {
if let Some(old_test) = res.err.insert(test.name.clone(), test) {
bail!("Duplicate test: {}", old_test.name)
Err(format!("Duplicate test: {}", old_test.name))?
}
}
}

View file

@ -1,6 +1,5 @@
use clap::{App, SubCommand};
use core::str;
use failure::bail;
use ra_tools::{
generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt,
Overwrite, Result, run_fuzzer, run_clippy,
@ -64,10 +63,8 @@ fn verify_installed_extensions() -> Result<()> {
run_with_output(r"code --list-extensions", ".")?
};
if !str::from_utf8(&exts.stdout)?.contains("ra-lsp") {
bail!(
"Could not install the Visual Studio Code extension. Please make sure you \
have at least NodeJS 10.x installed and try again."
);
Err("Could not install the Visual Studio Code extension. Please make sure you \
have at least NodeJS 10.x installed and try again.")?;
}
Ok(())
}
@ -79,7 +76,7 @@ fn fix_path_for_mac() -> Result<()> {
const ROOT_DIR: &str = "";
let home_dir = match env::var("HOME") {
Ok(home) => home,
Err(e) => bail!("Failed getting HOME from environment with error: {}.", e),
Err(e) => Err(format!("Failed getting HOME from environment with error: {}.", e))?,
};
[ROOT_DIR, &home_dir]
@ -93,7 +90,7 @@ fn fix_path_for_mac() -> Result<()> {
if !vscode_path.is_empty() {
let vars = match env::var_os("PATH") {
Some(path) => path,
None => bail!("Could not get PATH variable from env."),
None => Err("Could not get PATH variable from env.")?,
};
let mut paths = env::split_paths(&vars).collect::<Vec<_>>();