Handle missing default formatter

In the event that we cannot load our plugins, we shouldn't raise a
cryptic KeyError from our formatter.

Closes #320
This commit is contained in:
Ian Cordasco 2017-05-13 06:52:08 -05:00
parent b6c0cce3e6
commit 15ddc3aa2e
No known key found for this signature in database
GPG key ID: 656D3395E4A9791A
2 changed files with 20 additions and 1 deletions

View file

@ -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."""

View file

@ -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')