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)
```
This commit is contained in:
Travis Finkenauer 2022-02-15 15:25:44 -08:00 committed by GitHub
parent 1e78a2b258
commit 6c476127ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -26,7 +26,7 @@ fn main() {
let exit_code = match execute(&opts) {
Ok(code) => code,
Err(e) => {
eprintln!("{}", e);
eprintln!("{:#}", e);
1
}
};

View File

@ -364,7 +364,9 @@ fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
// find the project file yet, and continue searching.
Err(e) => {
if e.kind() != ErrorKind::NotFound {
return Err(e);
let ctx = format!("Failed to get metadata for config file {:?}", &config_file);
let err = anyhow::Error::new(e).context(ctx);
return Err(Error::new(ErrorKind::Other, err));
}
}
_ => {}