Skip to content

Better error message #6302

@appetrosyan

Description

@appetrosyan

I ran into a problem that was resolved by looking at #2057. It took longer than I'd like and the error message is not too helpful.

Currently if the project doesn't have rustfmt.toml in the workspace, cargo fmt checks all parent directories for a configuration file. This is not the expected behaviour, because as a user of Rust one assumes that going to the parent ends at the nearest workspace (and workspaces can't be nested). As such it is unclear which configuration file failed to parse.

So, the error message that looks like this,

Error: Decoding config file failed:
invalid type: integer `2021`, expected string
in `edition`

Please check your config file.

Should really read as more like this:

The file `/home/user/git/rustfmt.toml` failed to parse. 
Invalid type: Integer `2021`, expected string 

Please check `/home/user/git/rustfmt.toml`. 

Ideally, of course the error message can be brought in line with the quality of rustc errors, looking more like

The file `/home/user/git/rustfmt.toml` failed to parse. 
The `edition` variable has the wrong type: expected string, got 2021 (Integer). 

21: edition = 2021 

help: Add double quotes around `2021` in `/home/user/git/rustfmt.toml:21`. 

Metadata

Metadata

Assignees

Labels

good first issueIssues up for grabs, also good candidates for new rustfmt contributors

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions