mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-11 15:24:18 +00:00
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:
parent
b6c0cce3e6
commit
15ddc3aa2e
2 changed files with 20 additions and 1 deletions
|
|
@ -13,6 +13,10 @@ class EarlyQuit(Flake8Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ExecutionError(Flake8Exception):
|
||||||
|
"""Exception raised during execution of Flake8."""
|
||||||
|
|
||||||
|
|
||||||
class FailedToLoadPlugin(Flake8Exception):
|
class FailedToLoadPlugin(Flake8Exception):
|
||||||
"""Exception raised when a plugin fails to load."""
|
"""Exception raised when a plugin fails to load."""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -195,9 +195,19 @@ class Application(object):
|
||||||
elif 2 <= self.options.quiet:
|
elif 2 <= self.options.quiet:
|
||||||
format_plugin = 'quiet-nothing'
|
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:
|
if formatter_class is None:
|
||||||
formatter_class = self.formatting_plugins.get(
|
formatter_class = self.formatting_plugins.get(
|
||||||
format_plugin, self.formatting_plugins['default']
|
format_plugin, default_formatter
|
||||||
).execute
|
).execute
|
||||||
|
|
||||||
self.formatter = formatter_class(self.options)
|
self.formatter = formatter_class(self.options)
|
||||||
|
|
@ -332,6 +342,11 @@ class Application(object):
|
||||||
LOG.exception(exc)
|
LOG.exception(exc)
|
||||||
self.file_checker_manager._force_cleanup()
|
self.file_checker_manager._force_cleanup()
|
||||||
self.catastrophic_failure = True
|
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:
|
except exceptions.EarlyQuit:
|
||||||
self.catastrophic_failure = True
|
self.catastrophic_failure = True
|
||||||
print('... stopped while processing files')
|
print('... stopped while processing files')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue