-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
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
.gitignorecan't be parsed, just emit a warning and go on (fine, but I'm hesitant) - Stop using
.gitignoreautomatically (probably too much disruption potential)
Additional context
I thought of this when triaging #2351.