Prevent panicking against directories or non-existent files
@@ -258,6 +258,13 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
let mut error_summary = Summary::new();
for file in files {
+ if !file.exists() {
+ println!("Error: file `{}` does not exist", file.to_str().unwrap());
+ error_summary.add_operational_error();
+ } else if file.is_dir() {
+ println!("Error: `{}` is a directory", file.to_str().unwrap());
+ error_summary.add_operational_error();
+ } else {
// Check the file directory if the config-path could not be read or not provided
if path.is_none() {
let (config_tmp, path_tmp) = resolve_config(file.parent().unwrap())?;
@@ -274,6 +281,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
options.clone().apply_to(&mut config);
error_summary.add(run(Input::File(file), &config));
}
+ }
Ok(error_summary)
}
}
