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

Internal error when an undefined section is used #1562

Closed
epage opened this issue Oct 14, 2020 · 2 comments
Closed

Internal error when an undefined section is used #1562

epage opened this issue Oct 14, 2020 · 2 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request Hacktoberfest
Milestone

Comments

@epage
Copy link

epage commented Oct 14, 2020

As I was trying to resolve my use case from #761, I assumed I could do sections=FUTURE,STDLIB,THIRDPARTY combined with the default section to get the behavior I wanted but I get an internal error

ERROR: Unrecoverable exception thrown when parsing /Users/edpage/src/trustedpath/ddi/bin/command_sync.py! This should NEVER happen.
If encountered, please open an issue: https://github.com/PyCQA/isort/issues/new
Traceback (most recent call last):
  File "/Users/edpage/.cache/ddi/venv_fmt/bin/isort", line 8, in <module>
    sys.exit(main())
  File "/Users/edpage/.cache/ddi/venv_fmt/lib/python3.8/site-packages/isort/main.py", line 953, in main
    for sort_attempt in attempt_iterator:
  File "/Users/edpage/.cache/ddi/venv_fmt/lib/python3.8/site-packages/isort/main.py", line 939, in <genexpr>
    sort_imports(  # type: ignore
  File "/Users/edpage/.cache/ddi/venv_fmt/lib/python3.8/site-packages/isort/main.py", line 95, in sort_imports
    incorrectly_sorted = not api.sort_file(
  File "/Users/edpage/.cache/ddi/venv_fmt/lib/python3.8/site-packages/isort/api.py", line 324, in sort_file
    changed = sort_stream(
  File "/Users/edpage/.cache/ddi/venv_fmt/lib/python3.8/site-packages/isort/api.py", line 158, in sort_stream
    changed = core.process(
  File "/Users/edpage/.cache/ddi/venv_fmt/lib/python3.8/site-packages/isort/core.py", line 332, in process
    parsed_content = parse.file_contents(import_section, config=config)
  File "/Users/edpage/.cache/ddi/venv_fmt/lib/python3.8/site-packages/isort/parse.py", line 527, in file_contents
    straight_import |= imports[placed_module][type_of_import].get(  # type: ignore
KeyError: 'FIRSTPARTY'

I've since found an alternative to what I was trying to accomplish but I figured it'd be good to raise awareness of this in case it sparked interest in resolving. Example resolutions include

  • Unknown sections fall back to the default
  • Provide a nicer user facing error to tell them what went wrong and clarify this in the docs.

This was with isort 5.6.4 in Python 3.8

@timothycrosley timothycrosley added this to the 5.7.0 milestone Oct 15, 2020
@timothycrosley
Copy link
Member

I agree! This error message is far from ideal, and better documentation overall would be very helpful here.
Thanks for raising this issue!

@timothycrosley timothycrosley added documentation Improvements or additions to documentation enhancement New feature or request Hacktoberfest labels Oct 15, 2020
@ichard26
Copy link

ichard26 commented Nov 4, 2020

Heya, it appears that this should be closed as PR #1572 has been merged. The PR author simply forgot that each issue you want to close automatically needs the keyword before it.

Fixes #1570 #1562

Just a triager of Black doing what they do best :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request Hacktoberfest
Projects
None yet
Development

No branches or pull requests

3 participants