Skip to content

Commit

Permalink
Catch KeyError on missing sections and warn
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydesl committed Oct 22, 2020
1 parent f39ec52 commit 4e3a4f5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion isort/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .format import create_terminal_printer
from .logo import ASCII_ART
from .profiles import profiles
from .settings import VALID_PY_TARGETS, Config, WrapModes
from .settings import DEFAULT_CONFIG, VALID_PY_TARGETS, Config, WrapModes

try:
from .setuptools_commands import ISortCommand # noqa: F401
Expand Down Expand Up @@ -101,6 +101,12 @@ def sort_imports(
)
except FileSkipped:
skipped = True
except KeyError as error:
if error.args[0] in DEFAULT_CONFIG.sections:
incorrectly_sorted = True
warn(f"Cannot parse {file_name} because {error} missing in `sections` config")
else:
raise
return SortAttempt(incorrectly_sorted, skipped, True)
except (OSError, ValueError) as error:
warn(f"Unable to parse file {file_name} due to {error}")
Expand Down

0 comments on commit 4e3a4f5

Please sign in to comment.