summaryrefslogtreecommitdiff
path: root/src/flake8
diff options
context:
space:
mode:
authorIan Stapleton Cordasco <graffatcolmingov@gmail.com>2018-01-01 00:50:52 +0000
committerIan Stapleton Cordasco <graffatcolmingov@gmail.com>2018-01-01 00:50:52 +0000
commitf0d63a5a998011d95eaa31c994a295a085bd8000 (patch)
treeb843a7e8c305266b6b46d22a41c1ba4f9b5f7e6f /src/flake8
parent8ac129213db2ad29c0287cca4742539f62c91168 (diff)
parent30431155513c177a52c0f8ce0e6ed6d6274c6144 (diff)
downloadflake8-f0d63a5a998011d95eaa31c994a295a085bd8000.tar.gz
Merge branch 'handle-broken-plugins-nicer' into 'master'
Implement better UX around broken plugins See merge request pycqa/flake8!221
Diffstat (limited to 'src/flake8')
-rw-r--r--src/flake8/checker.py10
-rw-r--r--src/flake8/exceptions.py19
-rw-r--r--src/flake8/main/application.py7
3 files changed, 34 insertions, 2 deletions
diff --git a/src/flake8/checker.py b/src/flake8/checker.py
index 6e53cb5..7a18ce5 100644
--- a/src/flake8/checker.py
+++ b/src/flake8/checker.py
@@ -432,7 +432,15 @@ class FileChecker(object):
plugin=plugin,
exception=ae,
)
- return plugin['plugin'](**arguments)
+ try:
+ return plugin['plugin'](**arguments)
+ except Exception as all_exc:
+ LOG.critical('Plugin %s raised an unexpected exception',
+ plugin['name'])
+ raise exceptions.PluginExecutionFailed(
+ plugin=plugin,
+ excetion=all_exc,
+ )
@staticmethod
def _extract_syntax_information(exception):
diff --git a/src/flake8/exceptions.py b/src/flake8/exceptions.py
index 13e8996..c7217f5 100644
--- a/src/flake8/exceptions.py
+++ b/src/flake8/exceptions.py
@@ -76,6 +76,25 @@ class PluginRequestedUnknownParameters(Flake8Exception):
'exc': self.original_exception}
+class PluginExecutionFailed(Flake8Exception):
+ """The plugin failed during execution."""
+
+ FORMAT = '"%(name)s" failed during execution due to "%(exc)s"'
+
+ def __init__(self, *args, **kwargs):
+ """Utilize keyword arguments for message generation."""
+ self.original_exception = kwargs.pop('exception')
+ self.plugin = kwargs.pop('plugin')
+ super(PluginExecutionFailed, self).__init__(
+ str(self), *args, **kwargs
+ )
+
+ def __str__(self):
+ """Format our exception message."""
+ return self.FORMAT % {'name': self.plugin['plugin_name'],
+ 'exc': self.original_exception}
+
+
class HookInstallationError(Flake8Exception):
"""Parent exception for all hooks errors."""
diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py
index 233b9af..aed6175 100644
--- a/src/flake8/main/application.py
+++ b/src/flake8/main/application.py
@@ -309,7 +309,12 @@ class Application(object):
if self.running_against_diff:
files = sorted(self.parsed_diff)
self.file_checker_manager.start(files)
- self.file_checker_manager.run()
+ try:
+ self.file_checker_manager.run()
+ except exceptions.PluginExecutionFailed as plugin_failed:
+ print(str(plugin_failed))
+ print('Run flake8 with greater verbosity to see more details')
+ self.catastrophic_failure = True
LOG.info('Finished running')
self.file_checker_manager.stop()
self.end_time = time.time()