Skip to content

Commit e06c9c8

Browse files
committed
Allow io::Error to live longer before being wrapped in a failure::Error
1 parent b7df23c commit e06c9c8

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/config/config_type.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,12 @@ macro_rules! create_config {
305305
///
306306
/// Return a `Config` if the config could be read and parsed from
307307
/// the file, Error otherwise.
308-
pub(super) fn from_toml_path(file_path: &Path) -> Result<Config, ::failure::Error> {
308+
pub(super) fn from_toml_path(file_path: &Path) -> Result<Config, Error> {
309309
let mut file = File::open(&file_path)?;
310310
let mut toml = String::new();
311311
file.read_to_string(&mut toml)?;
312312
Config::from_toml(&toml, file_path.parent().unwrap())
313-
.map_err(::failure::err_msg)
313+
.map_err(|err| Error::new(ErrorKind::InvalidData, err))
314314
}
315315

316316
/// Resolve the config for input in `dir`.
@@ -322,12 +322,12 @@ macro_rules! create_config {
322322
///
323323
/// Returns the `Config` to use, and the path of the project file if there was
324324
/// one.
325-
pub(super) fn from_resolved_toml_path(dir: &Path) -> Result<(Config, Option<PathBuf>), ::failure::Error> {
325+
pub(super) fn from_resolved_toml_path(dir: &Path) -> Result<(Config, Option<PathBuf>), Error> {
326326

327327
/// Try to find a project file in the given directory and its parents.
328328
/// Returns the path of a the nearest project file if one exists,
329329
/// or `None` if no project file was found.
330-
fn resolve_project_file(dir: &Path) -> Result<Option<PathBuf>, ::failure::Error> {
330+
fn resolve_project_file(dir: &Path) -> Result<Option<PathBuf>, Error> {
331331
let mut current = if dir.is_relative() {
332332
env::current_dir()?.join(dir)
333333
} else {

src/config/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@ use regex::Regex;
1212
use std::cell::Cell;
1313
use std::default::Default;
1414
use std::fs::File;
15-
use std::io::{ErrorKind, Read};
15+
use std::io::{Error, ErrorKind, Read};
1616
use std::path::{Path, PathBuf};
1717
use std::{env, fs};
1818

19-
use FmtResult;
20-
2119
use config::config_type::ConfigType;
2220
use config::file_lines::FileLines;
2321
pub use config::lists::*;
2422
pub use config::options::*;
25-
use failure::Error;
2623

2724
#[macro_use]
2825
pub mod config_type;
@@ -155,7 +152,7 @@ create_config! {
155152
pub fn load_config(
156153
file_path: Option<&Path>,
157154
options: Option<&CliOptions>,
158-
) -> FmtResult<(Config, Option<PathBuf>)> {
155+
) -> Result<(Config, Option<PathBuf>), Error> {
159156
let over_ride = match options {
160157
Some(opts) => config_path(opts)?,
161158
None => None,
@@ -180,7 +177,7 @@ pub fn load_config(
180177
// Check for the presence of known config file names (`rustfmt.toml, `.rustfmt.toml`) in `dir`
181178
//
182179
// Return the path if a config file exists, empty if no file exists, and Error for IO errors
183-
fn get_toml_path(dir: &Path) -> FmtResult<Option<PathBuf>> {
180+
fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
184181
const CONFIG_FILE_NAMES: [&str; 2] = [".rustfmt.toml", "rustfmt.toml"];
185182
for config_file_name in &CONFIG_FILE_NAMES {
186183
let config_file = dir.join(config_file_name);
@@ -192,7 +189,7 @@ fn get_toml_path(dir: &Path) -> FmtResult<Option<PathBuf>> {
192189
// find the project file yet, and continue searching.
193190
Err(e) => {
194191
if e.kind() != ErrorKind::NotFound {
195-
return Err(Error::from(e));
192+
return Err(e);
196193
}
197194
}
198195
_ => {}
@@ -201,11 +198,14 @@ fn get_toml_path(dir: &Path) -> FmtResult<Option<PathBuf>> {
201198
Ok(None)
202199
}
203200

204-
fn config_path(options: &CliOptions) -> FmtResult<Option<PathBuf>> {
205-
let config_path_not_found = |path: &str| -> FmtResult<Option<PathBuf>> {
206-
Err(format_err!(
207-
"Error: unable to find a config file for the given path: `{}`",
208-
path
201+
fn config_path(options: &CliOptions) -> Result<Option<PathBuf>, Error> {
202+
let config_path_not_found = |path: &str| -> Result<Option<PathBuf>, Error> {
203+
Err(Error::new(
204+
ErrorKind::NotFound,
205+
format!(
206+
"Error: unable to find a config file for the given path: `{}`",
207+
path
208+
),
209209
))
210210
};
211211

0 commit comments

Comments
 (0)