]> git.lizzy.rs Git - rust.git/commitdiff
Allow `io::Error` to live longer before being wrapped in a `failure::Error`
authorTibo <delor.thibault@gmail.com>
Thu, 26 Apr 2018 04:20:06 +0000 (14:20 +1000)
committerTibo <delor.thibault@gmail.com>
Thu, 26 Apr 2018 04:39:10 +0000 (14:39 +1000)
src/config/config_type.rs
src/config/mod.rs

index 828dfe8b024f1f81c7bf817d1f764db3864f5611..3b9ca90350cfc779286d2605b85e0db841e4c488 100644 (file)
@@ -305,12 +305,12 @@ pub fn override_value(&mut self, key: &str, val: &str)
             ///
             /// Return a `Config` if the config could be read and parsed from
             /// the file, Error otherwise.
-            pub(super) fn from_toml_path(file_path: &Path) -> Result<Config, ::failure::Error> {
+            pub(super) fn from_toml_path(file_path: &Path) -> Result<Config, Error> {
                 let mut file = File::open(&file_path)?;
                 let mut toml = String::new();
                 file.read_to_string(&mut toml)?;
                 Config::from_toml(&toml, file_path.parent().unwrap())
-                    .map_err(::failure::err_msg)
+                    .map_err(|err| Error::new(ErrorKind::InvalidData, err))
             }
 
             /// Resolve the config for input in `dir`.
@@ -322,12 +322,12 @@ pub(super) fn from_toml_path(file_path: &Path) -> Result<Config, ::failure::Erro
             ///
             /// Returns the `Config` to use, and the path of the project file if there was
             /// one.
-            pub(super) fn from_resolved_toml_path(dir: &Path) -> Result<(Config, Option<PathBuf>), ::failure::Error> {
+            pub(super) fn from_resolved_toml_path(dir: &Path) -> Result<(Config, Option<PathBuf>), Error> {
 
                 /// Try to find a project file in the given directory and its parents.
                 /// Returns the path of a the nearest project file if one exists,
                 /// or `None` if no project file was found.
-                fn resolve_project_file(dir: &Path) -> Result<Option<PathBuf>, ::failure::Error> {
+                fn resolve_project_file(dir: &Path) -> Result<Option<PathBuf>, Error> {
                     let mut current = if dir.is_relative() {
                         env::current_dir()?.join(dir)
                     } else {
index 8c90c556b4d608d7494d08c4c2b01a57ac61ca23..23897f3cc32aa37043ad32c7b6e3a87406b4232f 100644 (file)
 use std::cell::Cell;
 use std::default::Default;
 use std::fs::File;
-use std::io::{ErrorKind, Read};
+use std::io::{Error, ErrorKind, Read};
 use std::path::{Path, PathBuf};
 use std::{env, fs};
 
-use FmtResult;
-
 use config::config_type::ConfigType;
 use config::file_lines::FileLines;
 pub use config::lists::*;
 pub use config::options::*;
-use failure::Error;
 
 #[macro_use]
 pub mod config_type;
 pub fn load_config(
     file_path: Option<&Path>,
     options: Option<&CliOptions>,
-) -> FmtResult<(Config, Option<PathBuf>)> {
+) -> Result<(Config, Option<PathBuf>), Error> {
     let over_ride = match options {
         Some(opts) => config_path(opts)?,
         None => None,
@@ -180,7 +177,7 @@ pub fn load_config(
 // Check for the presence of known config file names (`rustfmt.toml, `.rustfmt.toml`) in `dir`
 //
 // Return the path if a config file exists, empty if no file exists, and Error for IO errors
-fn get_toml_path(dir: &Path) -> FmtResult<Option<PathBuf>> {
+fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
     const CONFIG_FILE_NAMES: [&str; 2] = [".rustfmt.toml", "rustfmt.toml"];
     for config_file_name in &CONFIG_FILE_NAMES {
         let config_file = dir.join(config_file_name);
@@ -192,7 +189,7 @@ fn get_toml_path(dir: &Path) -> FmtResult<Option<PathBuf>> {
             // find the project file yet, and continue searching.
             Err(e) => {
                 if e.kind() != ErrorKind::NotFound {
-                    return Err(Error::from(e));
+                    return Err(e);
                 }
             }
             _ => {}
@@ -201,11 +198,14 @@ fn get_toml_path(dir: &Path) -> FmtResult<Option<PathBuf>> {
     Ok(None)
 }
 
-fn config_path(options: &CliOptions) -> FmtResult<Option<PathBuf>> {
-    let config_path_not_found = |path: &str| -> FmtResult<Option<PathBuf>> {
-        Err(format_err!(
-            "Error: unable to find a config file for the given path: `{}`",
-            path
+fn config_path(options: &CliOptions) -> Result<Option<PathBuf>, Error> {
+    let config_path_not_found = |path: &str| -> Result<Option<PathBuf>, Error> {
+        Err(Error::new(
+            ErrorKind::NotFound,
+            format!(
+                "Error: unable to find a config file for the given path: `{}`",
+                path
+            ),
         ))
     };