Skip to content

Commit

Permalink
Gracefully fail on missing default sections
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydesl committed Oct 25, 2020
1 parent bacd6c7 commit 435d2cd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 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 @@ -109,6 +109,18 @@ def sort_imports(
if config.verbose:
warn(f"Encoding not supported for {file_name}")
return SortAttempt(incorrectly_sorted, skipped, False)
except KeyError as error:
if error.args[0] not in DEFAULT_CONFIG.sections:
_print_hard_fail(config, offending_file=file_name)
raise
msg = (
f"Found {error} imports while parsing, but {error} was not included "
"in the `sections` setting of your config. Please add it before continuing\n"
"See https://pycqa.github.io/isort/#custom-sections-and-ordering "
"for more info."
)
_print_hard_fail(config, message=msg)
sys.exit(os.EX_CONFIG)
except Exception:
_print_hard_fail(config, offending_file=file_name)
raise
Expand Down

0 comments on commit 435d2cd

Please sign in to comment.