PyCQA / isort

A Python utility / library to sort imports.
https://pycqa.github.io/isort/
MIT License
6.49k stars 580 forks source link

Ran into `ERROR: Unrecoverable exception thrown when parsing <filepath>` #2243

Open pmlk opened 7 months ago

pmlk commented 7 months ago

While I was refactoring some of my imports I ran into ERROR: Unrecoverable exception thrown when parsing <filepath> This should NEVER happen. If encountered, please open an issue: https://github.com/PyCQA/isort/issues/new

Since it nicely asked to submit an issue, here I am.

I quickly found the issue and was able to fix it manually: one of my imports was missing a space between . and import:

from ..import some_module

Adding the missing space fixed the problem.

Hope it helps someone. Feel free to close if you deem it irrelevant to this library.

Traceback ``` Traceback (most recent call last): File "/Users/pmlk/Library/Caches/pypoetry/virtualenvs/backend-6xSfTYP9-py3.9/bin/isort", line 8, in sys.exit(main()) File "/Users/pmlk/Library/Caches/pypoetry/virtualenvs/backend-6xSfTYP9-py3.9/lib/python3.9/site-packages/isort/main.py", line 1226, in main for sort_attempt in attempt_iterator: File "/Users/pmlk/Library/Caches/pypoetry/virtualenvs/backend-6xSfTYP9-py3.9/lib/python3.9/site-packages/isort/main.py", line 1210, in sort_imports( # type: ignore File "/Users/pmlk/Library/Caches/pypoetry/virtualenvs/backend-6xSfTYP9-py3.9/lib/python3.9/site-packages/isort/main.py", line 93, in sort_imports incorrectly_sorted = not api.sort_file( File "/Users/pmlk/Library/Caches/pypoetry/virtualenvs/backend-6xSfTYP9-py3.9/lib/python3.9/site-packages/isort/api.py", line 429, in sort_file changed = sort_stream( File "/Users/pmlk/Library/Caches/pypoetry/virtualenvs/backend-6xSfTYP9-py3.9/lib/python3.9/site-packages/isort/api.py", line 210, in sort_stream changed = core.process( File "/Users/pmlk/Library/Caches/pypoetry/virtualenvs/backend-6xSfTYP9-py3.9/lib/python3.9/site-packages/isort/core.py", line 422, in process parsed_content = parse.file_contents(import_section, config=config) File "/Users/pmlk/Library/Caches/pypoetry/virtualenvs/backend-6xSfTYP9-py3.9/lib/python3.9/site-packages/isort/parse.py", line 522, in file_contents if "," in import_string.split(just_imports[-1])[-1]: IndexError: list index out of range ```