Fall down of failures

This commit is contained in:
Muhammad Mominul Huque 2019-06-16 00:48:50 +06:00
parent 41c56c8a0d
commit 91510db6d8
No known key found for this signature in database
GPG key ID: 37AF141540DE557D
5 changed files with 19 additions and 24 deletions

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<_>>();