Skip to content

Commit 47a0bef

Browse files
committed
Return a more verbose error when formatting a file fails
Expands the error message returned if the after_file function fails to also include path_str. This allows users to better identify files that are not being formatted.
1 parent 560b054 commit 47a0bef

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,14 @@ where
325325
}
326326
visitor.format_separate_mod(module, &*filemap);
327327

328-
has_diff |= after_file(path_str, &mut visitor.buffer)?;
328+
has_diff |= match after_file(path_str, &mut visitor.buffer) {
329+
Ok(result) => result,
330+
Err(e) => {
331+
// Create a new error with path_str to help users see which files failed
332+
let mut err_msg = path_str.to_string() + &": ".to_string() + &e.to_string();
333+
return Err(io::Error::new(e.kind(), err_msg));
334+
}
335+
};
329336

330337
result.push((path_str.to_owned(), visitor.buffer));
331338
}

0 commit comments

Comments
 (0)