mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-15 00:44:44 +00:00
Merge branch 'handle-broken-plugins-nicer' into 'master'
Implement better UX around broken plugins See merge request pycqa/flake8!221
This commit is contained in:
commit
f0d63a5a99
3 changed files with 34 additions and 2 deletions
|
|
@ -432,7 +432,15 @@ class FileChecker(object):
|
||||||
plugin=plugin,
|
plugin=plugin,
|
||||||
exception=ae,
|
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
|
@staticmethod
|
||||||
def _extract_syntax_information(exception):
|
def _extract_syntax_information(exception):
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,25 @@ class PluginRequestedUnknownParameters(Flake8Exception):
|
||||||
'exc': self.original_exception}
|
'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):
|
class HookInstallationError(Flake8Exception):
|
||||||
"""Parent exception for all hooks errors."""
|
"""Parent exception for all hooks errors."""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -309,7 +309,12 @@ class Application(object):
|
||||||
if self.running_against_diff:
|
if self.running_against_diff:
|
||||||
files = sorted(self.parsed_diff)
|
files = sorted(self.parsed_diff)
|
||||||
self.file_checker_manager.start(files)
|
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')
|
LOG.info('Finished running')
|
||||||
self.file_checker_manager.stop()
|
self.file_checker_manager.stop()
|
||||||
self.end_time = time.time()
|
self.end_time = time.time()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue