summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2017-05-13 06:52:08 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2017-05-13 06:52:08 -0500
commit15ddc3aa2e32187a2079d87f9e91fd2e6f03f60c (patch)
treea7c0cadb31bb2509b8806e92248934a8881c3d2c /src
parentb6c0cce3e6aa450a2d130bf59b19b7cd34f1291c (diff)
downloadflake8-15ddc3aa2e32187a2079d87f9e91fd2e6f03f60c.tar.gz
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
Diffstat (limited to 'src')
-rw-r--r--src/flake8/exceptions.py4
-rw-r--r--src/flake8/main/application.py17
2 files changed, 20 insertions, 1 deletions
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')