diff --git a/src/flake8/exceptions.py b/src/flake8/exceptions.py index cf8aae3..13e8996 100644 --- a/src/flake8/exceptions.py +++ b/src/flake8/exceptions.py @@ -13,6 +13,10 @@ class EarlyQuit(Flake8Exception): pass +class ExecutionError(Flake8Exception): + """Exception raised during execution of Flake8.""" + + class FailedToLoadPlugin(Flake8Exception): """Exception raised when a plugin fails to load.""" diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py index 2eae382..01912b3 100644 --- a/src/flake8/main/application.py +++ b/src/flake8/main/application.py @@ -195,9 +195,19 @@ class Application(object): elif 2 <= self.options.quiet: format_plugin = 'quiet-nothing' + try: + default_formatter = self.formatting_plugins['default'] + except KeyError: + raise exceptions.ExecutionError( + "The 'default' Flake8 formatting plugin is unavailable. " + "This usually indicates that your setuptools is too old. " + "Please upgrade setuptools. If that does not fix the issue" + " please file an issue." + ) + if formatter_class is None: formatter_class = self.formatting_plugins.get( - format_plugin, self.formatting_plugins['default'] + format_plugin, default_formatter ).execute self.formatter = formatter_class(self.options) @@ -332,6 +342,11 @@ class Application(object): LOG.exception(exc) self.file_checker_manager._force_cleanup() self.catastrophic_failure = True + except exceptions.ExecutionError as exc: + print('There was a critical error during execution of Flake8:') + print(exc.message) + LOG.exception(exc) + self.catastrophic_failure = True except exceptions.EarlyQuit: self.catastrophic_failure = True print('... stopped while processing files')