Skip to content

Commit 6c47612

Browse files
authored
Add context to get_toml_path() error (#5207)
* rustfmt: print full error chain * Add context to get_toml_path() error Instead of an error like: ``` Permission denied (os error 13) ``` Gives error like: ``` Failed to get metadata for config file "/root/.rustfmt.toml": Permission denied (os error 13) ```
1 parent 1e78a2b commit 6c47612

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/bin/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() {
2626
let exit_code = match execute(&opts) {
2727
Ok(code) => code,
2828
Err(e) => {
29-
eprintln!("{}", e);
29+
eprintln!("{:#}", e);
3030
1
3131
}
3232
};

src/config/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@ fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
364364
// find the project file yet, and continue searching.
365365
Err(e) => {
366366
if e.kind() != ErrorKind::NotFound {
367-
return Err(e);
367+
let ctx = format!("Failed to get metadata for config file {:?}", &config_file);
368+
let err = anyhow::Error::new(e).context(ctx);
369+
return Err(Error::new(ErrorKind::Other, err));
368370
}
369371
}
370372
_ => {}

0 commit comments

Comments
 (0)