Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading error hint about unknown configuration file keys #12359

Open
pradyunsg opened this issue Jul 17, 2024 · 3 comments
Open

Misleading error hint about unknown configuration file keys #12359

pradyunsg opened this issue Jul 17, 2024 · 3 comments
Labels
bug Something isn't working configuration Related to settings and configuration

Comments

@pradyunsg
Copy link

pradyunsg commented Jul 17, 2024

Version: 0.5.2

Reproduction instructions

  1. Create a ruff.toml file with the contents:

    extend-select = [
        "W", # pycodestyle warnings
        "I", # isort
        "N", # pep8-naming
        "D", # pydocstyle
        "B", # flake8-bugbear
        "PYI" # flake8-pyi
    ]
    
    # Group errors by file.
    output-format = "grouped"
    
    # Show source context of error.
    show-source = true
    
    # Show summary of fixes.
    show-fixes = true
  2. Create a src/foo.py file with no contents.

  3. Run ruff check and see the problematic error message.

Output

ruff check
ruff failed
  Cause: Failed to parse /Users/[...]/ruff.toml
  Cause: TOML parse error at line 1, column 1
  |
1 | extend-select = [
  | ^^^^^^^^^^^^^^^^^
unknown field `show-source`

The error message points to the line about extend-select when complaining about show-source as the key that is unknown. It would be better for the error to point at line 14 entirely OR, ideally, point only at show-source part of that line since that's the key in the key-value pair in the configuration file that is unknown.

@pradyunsg pradyunsg changed the title Misleading error hint about invalid configuration file keys Misleading error hint about unknown configuration file keys Jul 17, 2024
@MichaReiser
Copy link
Member

That makes sense. Although I don't think there's much that we can do about it other than writing our own toml parser. The error message comes directly from the toml crate

let contents = std::fs::read_to_string(path.as_ref())
.with_context(|| format!("Failed to read {}", path.as_ref().display()))?;
toml::from_str(&contents)
.with_context(|| format!("Failed to parse {}", path.as_ref().display()))

@MichaReiser
Copy link
Member

Could be related to toml-rs/toml#589

@charliermarsh charliermarsh added bug Something isn't working configuration Related to settings and configuration labels Jul 17, 2024
@charliermarsh
Copy link
Member

Yeah that's a shame. Thanks @pradyunsg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working configuration Related to settings and configuration
Projects
None yet
Development

No branches or pull requests

3 participants