///
/// 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`.
///
/// 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 {
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,
// 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);
// find the project file yet, and continue searching.
Err(e) => {
if e.kind() != ErrorKind::NotFound {
- return Err(Error::from(e));
+ return Err(e);
}
}
_ => {}
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
+ ),
))
};