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

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

Closed
ichard26 opened this issue Jul 4, 2021 · 0 comments · Fixed by #2414
Closed

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

ichard26 opened this issue Jul 4, 2021 · 0 comments · Fixed by #2414
Labels
C: configuration CLI and configuration good first issue Good for newcomers S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: enhancement New feature or request

Comments

@ichard26
Copy link
Collaborator

ichard26 commented Jul 4, 2021

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.

@ichard26 ichard26 added T: enhancement New feature or request good first issue Good for newcomers C: configuration CLI and configuration S: accepted The changes in this design / enhancement issue have been accepted and can be implemented labels Jul 4, 2021
nipunn1313 added a commit to nipunn1313/black that referenced this issue Aug 7, 2021
nipunn1313 added a commit to nipunn1313/black that referenced this issue Aug 7, 2021
nipunn1313 added a commit to nipunn1313/black that referenced this issue Aug 19, 2021
ichard26 pushed a commit that referenced this issue Aug 20, 2021
Fixes #2359.

This commit now makes Black exit with an user-friendly error message if a
.gitignore file couldn't be parsed -- a massive improvement over an opaque
traceback!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: configuration CLI and configuration good first issue Good for newcomers S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant