Skip to content

Present a more user-friendly error if .gitgignore #2359

@ichard26

Description

@ichard26

Is your feature request related to a problem? Please describe.

Yes. When .gitignore is invalid, Black crashes with a confusing IndexError exception and it's not obvious that the .gitignore file is the issue. This is worsen by the fact, it's non-obvious Black uses .gitignore at all (maintainer note: it's been documented so it's fine, just describing how this is even worse of a problem than at first glance).

This is also a problem if say reading fails for some reason.

Describe the solution you'd like

If an exception is raised within the get_gitignore function, capture it and present a more user-friendly error without an unnecessary traceback and with a quick mention of .gitignore.

Describe alternatives you've considered

  • Continue operation even if .gitignore can't be parsed, just emit a warning and go on (fine, but I'm hesitant)
  • Stop using .gitignore automatically (probably too much disruption potential)

Additional context

I thought of this when triaging #2351.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: configurationCLI and configurationS: acceptedThe changes in this design / enhancement issue have been accepted and can be implementedT: enhancementNew feature or requestgood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions