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

"IndexError: list index out of range" on all files in folder #2351

Closed
adamklaff opened this issue Jul 1, 2021 · 4 comments
Closed

"IndexError: list index out of range" on all files in folder #2351

adamklaff opened this issue Jul 1, 2021 · 4 comments
Labels
C: file collection Related to file collection (e.g. gitignore & cache) or file discovery and all of its configuration. T: user support OP looking for assistance or answers to a question

Comments

@adamklaff
Copy link

adamklaff commented Jul 1, 2021

I'm running black via pipx, and I am getting this on every file I run black on in my project folder. If I move the file outside my project folder, it will process. Any ideas?

Traceback (most recent call last):
File "/Users/user1/.local/bin/black", line 8, in
sys.exit(patched_main())
File "/Users/user1/.local/pipx/venvs/black/lib/python3.9/site-packages/black/init.py", line 1128, in patched_main
main()
File "/Users/user1/.local/pipx/venvs/black/lib/python3.9/site-packages/click/core.py", line 1137, in call
return self.main(*args, **kwargs)
File "/Users/user1/.local/pipx/venvs/black/lib/python3.9/site-packages/click/core.py", line 1062, in main
rv = self.invoke(ctx)
File "/Users/user1/.local/pipx/venvs/black/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/user1/.local/pipx/venvs/black/lib/python3.9/site-packages/click/core.py", line 763, in invoke
return __callback(*args, **kwargs)
File "/Users/user1/.local/pipx/venvs/black/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "/Users/user1/.local/pipx/venvs/black/lib/python3.9/site-packages/black/init.py", line 410, in main
sources = get_sources(
File "/Users/user1/.local/pipx/venvs/black/lib/python3.9/site-packages/black/init.py", line 476, in get_sources
gitignore = get_gitignore(root)
File "/Users/user1/.local/pipx/venvs/black/lib/python3.9/site-packages/black/files.py", line 123, in get_gitignore
return PathSpec.from_lines("gitwildmatch", lines)
File "/Users/user1/.local/pipx/venvs/black/lib/python3.9/site-packages/pathspec/pathspec.py", line 95, in from_lines
lines = [pattern_factory(line) for line in lines if line]
File "/Users/user1/.local/pipx/venvs/black/lib/python3.9/site-packages/pathspec/pathspec.py", line 95, in
lines = [pattern_factory(line) for line in lines if line]
File "/Users/user1/.local/pipx/venvs/black/lib/python3.9/site-packages/pathspec/pattern.py", line 83, in init
regex, include = self.pattern_to_regex(pattern)
File "/Users/user1/.local/pipx/venvs/black/lib/python3.9/site-packages/pathspec/patterns/gitwildmatch.py", line 112, in pattern_to_regex
if not pattern_segs[-1] and len(pattern_segs) > 1:
IndexError: list index out of range

@adamklaff adamklaff changed the title "IndexError: list index out of range" on all files "IndexError: list index out of range" on all filesm in folder Jul 1, 2021
@adamklaff
Copy link
Author

This was due to a misconfigured .gitignore file. Fixed.

@ichard26 ichard26 added C: file collection Related to file collection (e.g. gitignore & cache) or file discovery and all of its configuration. T: user support OP looking for assistance or answers to a question labels Jul 4, 2021
@ichard26
Copy link
Collaborator

ichard26 commented Jul 4, 2021

It's great you were able to fix the issue on your own @adamklaff but that uncaught exception + traceback probably wasn't the most easy thing to debug I can imagine! For that I've opened a new issue asking for a more user-friendly error to be emitted when the .gitignore related code blows up :) #2359

Thanks for the report and therefore idea!

@SebastiaanZ
Copy link

SebastiaanZ commented Jul 9, 2021

@adamklaff I was looking into your bug and I wasn't able to reproduce it. Do you happen to have the fragment of your .gitignore file that triggers the exception? I want to provide a nice solution for #2359.

Edit: A line with a single backslash (\) reproduces the exception.

@adamklaff
Copy link
Author

adamklaff commented Jul 9, 2021 via email

@adamklaff adamklaff changed the title "IndexError: list index out of range" on all filesm in folder "IndexError: list index out of range" on all files in folder Jul 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: file collection Related to file collection (e.g. gitignore & cache) or file discovery and all of its configuration. T: user support OP looking for assistance or answers to a question
Projects
None yet
Development

No branches or pull requests

3 participants