Skip to content

Commit 1541b2d

Browse files
bors[bot]mominul
andcommitted
Merge #1409
1409: The Fall down of failures r=matklad a=mominul :grin: 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 <[email protected]>
2 parents 924d4d7 + d3e74bf commit 1541b2d

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

Cargo.lock

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

crates/ra_tools/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ authors = ["rust-analyzer developers"]
66
publish = false
77

88
[dependencies]
9-
teraron = "0.0.1"
9+
teraron = "0.1.0"
1010
walkdir = "2.1.3"
1111
itertools = "0.8.0"
1212
clap = "2.32.0"
13-
failure = "0.1.4"

crates/ra_tools/src/bin/pre-commit.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use std::process::Command;
22

3-
use failure::bail;
4-
53
use ra_tools::{Result, run_rustfmt, run, project_root, Overwrite};
64

75
fn main() -> Result<()> {
@@ -19,7 +17,10 @@ fn update_staged() -> Result<()> {
1917
.current_dir(&root)
2018
.output()?;
2119
if !output.status.success() {
22-
bail!("`git diff --diff-filter=MAR --name-only --cached` exited with {}", output.status);
20+
Err(format!(
21+
"`git diff --diff-filter=MAR --name-only --cached` exited with {}",
22+
output.status
23+
))?;
2324
}
2425
for line in String::from_utf8(output.stdout)?.lines() {
2526
run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?;

crates/ra_tools/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use std::{
33
collections::HashMap,
44
path::{Path, PathBuf},
55
process::{Command, Output, Stdio},
6-
io::{Error, ErrorKind}
6+
io::{Error as IoError, ErrorKind},
7+
error::Error
78
};
89

9-
use failure::bail;
1010
use itertools::Itertools;
1111

1212
pub use teraron::{Mode, Overwrite, Verify};
1313

14-
pub type Result<T> = std::result::Result<T, failure::Error>;
14+
pub type Result<T> = std::result::Result<T, Box<dyn Error>>;
1515

1616
pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron";
1717
const GRAMMAR_DIR: &str = "crates/ra_parser/src/grammar";
@@ -128,7 +128,7 @@ pub fn install_format_hook() -> Result<()> {
128128
fs::copy("./target/debug/pre-commit", result_path)?;
129129
}
130130
} else {
131-
return Err(Error::new(ErrorKind::AlreadyExists, "Git hook already created").into());
131+
Err(IoError::new(ErrorKind::AlreadyExists, "Git hook already created"))?;
132132
}
133133
Ok(())
134134
}
@@ -224,7 +224,7 @@ where
224224
f(cmd.args(args).current_dir(proj_dir).stderr(Stdio::inherit()));
225225
let output = cmd.output()?;
226226
if !output.status.success() {
227-
bail!("`{}` exited with {}", cmdline, output.status);
227+
Err(format!("`{}` exited with {}", cmdline, output.status))?;
228228
}
229229
Ok(output)
230230
}
@@ -256,11 +256,11 @@ fn tests_from_dir(dir: &Path) -> Result<Tests> {
256256
for (_, test) in collect_tests(&text) {
257257
if test.ok {
258258
if let Some(old_test) = res.ok.insert(test.name.clone(), test) {
259-
bail!("Duplicate test: {}", old_test.name)
259+
Err(format!("Duplicate test: {}", old_test.name))?
260260
}
261261
} else {
262262
if let Some(old_test) = res.err.insert(test.name.clone(), test) {
263-
bail!("Duplicate test: {}", old_test.name)
263+
Err(format!("Duplicate test: {}", old_test.name))?
264264
}
265265
}
266266
}

crates/ra_tools/src/main.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use clap::{App, SubCommand};
22
use core::str;
3-
use failure::bail;
43
use ra_tools::{
54
generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt,
65
Overwrite, Result, run_fuzzer, run_clippy,
@@ -64,10 +63,8 @@ fn verify_installed_extensions() -> Result<()> {
6463
run_with_output(r"code --list-extensions", ".")?
6564
};
6665
if !str::from_utf8(&exts.stdout)?.contains("ra-lsp") {
67-
bail!(
68-
"Could not install the Visual Studio Code extension. Please make sure you \
69-
have at least NodeJS 10.x installed and try again."
70-
);
66+
Err("Could not install the Visual Studio Code extension. Please make sure you \
67+
have at least NodeJS 10.x installed and try again.")?;
7168
}
7269
Ok(())
7370
}
@@ -79,7 +76,7 @@ fn fix_path_for_mac() -> Result<()> {
7976
const ROOT_DIR: &str = "";
8077
let home_dir = match env::var("HOME") {
8178
Ok(home) => home,
82-
Err(e) => bail!("Failed getting HOME from environment with error: {}.", e),
79+
Err(e) => Err(format!("Failed getting HOME from environment with error: {}.", e))?,
8380
};
8481

8582
[ROOT_DIR, &home_dir]
@@ -93,7 +90,7 @@ fn fix_path_for_mac() -> Result<()> {
9390
if !vscode_path.is_empty() {
9491
let vars = match env::var_os("PATH") {
9592
Some(path) => path,
96-
None => bail!("Could not get PATH variable from env."),
93+
None => Err("Could not get PATH variable from env.")?,
9794
};
9895

9996
let mut paths = env::split_paths(&vars).collect::<Vec<_>>();

0 commit comments

Comments
 (0)