mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-12 15:44:17 +00:00
Handle AttributeErrors during parameter aggregation
Plugins do not have their parameters checked in advance, so when we try to aggregate parameters for a plugin, there's a chance it may request an attribute of the FileProcessor that simply does not exist. We catch this and re-raise it but we should also capture it in the checker manager and handle it appropriately there as well.
This commit is contained in:
parent
846bfafe6c
commit
47e3e65cc1
2 changed files with 41 additions and 5 deletions
|
|
@ -40,10 +40,17 @@ SERIAL_RETRY_ERRNOS = set([
|
||||||
|
|
||||||
def _run_checks_from_queue(process_queue, results_queue, statistics_queue):
|
def _run_checks_from_queue(process_queue, results_queue, statistics_queue):
|
||||||
LOG.info('Running checks in parallel')
|
LOG.info('Running checks in parallel')
|
||||||
for checker in iter(process_queue.get, 'DONE'):
|
try:
|
||||||
LOG.info('Checking "%s"', checker.filename)
|
for checker in iter(process_queue.get, 'DONE'):
|
||||||
checker.run_checks(results_queue, statistics_queue)
|
LOG.info('Checking "%s"', checker.filename)
|
||||||
results_queue.put('DONE')
|
checker.run_checks(results_queue, statistics_queue)
|
||||||
|
except exceptions.PluginRequestedUnknownParameters as exc:
|
||||||
|
print(str(exc))
|
||||||
|
except Exception as exc:
|
||||||
|
LOG.error('Unhandled exception occurred')
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
|
results_queue.put('DONE')
|
||||||
|
|
||||||
|
|
||||||
class Manager(object):
|
class Manager(object):
|
||||||
|
|
@ -356,6 +363,8 @@ class Manager(object):
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
LOG.warning('Flake8 was interrupted by the user')
|
LOG.warning('Flake8 was interrupted by the user')
|
||||||
raise exceptions.EarlyQuit('Early quit while running checks')
|
raise exceptions.EarlyQuit('Early quit while running checks')
|
||||||
|
finally:
|
||||||
|
self._force_cleanup()
|
||||||
|
|
||||||
def start(self, paths=None):
|
def start(self, paths=None):
|
||||||
"""Start checking files.
|
"""Start checking files.
|
||||||
|
|
@ -447,7 +456,14 @@ class FileChecker(object):
|
||||||
def run_check(self, plugin, **arguments):
|
def run_check(self, plugin, **arguments):
|
||||||
"""Run the check in a single plugin."""
|
"""Run the check in a single plugin."""
|
||||||
LOG.debug('Running %r with %r', plugin, arguments)
|
LOG.debug('Running %r with %r', plugin, arguments)
|
||||||
self.processor.keyword_arguments_for(plugin.parameters, arguments)
|
try:
|
||||||
|
self.processor.keyword_arguments_for(plugin.parameters, arguments)
|
||||||
|
except AttributeError as ae:
|
||||||
|
LOG.error('Plugin requested unknown parameters.')
|
||||||
|
raise exceptions.PluginRequestedUnknownParameters(
|
||||||
|
plugin=plugin,
|
||||||
|
exception=ae,
|
||||||
|
)
|
||||||
return plugin.execute(**arguments)
|
return plugin.execute(**arguments)
|
||||||
|
|
||||||
def run_ast_checks(self):
|
def run_ast_checks(self):
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,26 @@ class InvalidSyntax(Flake8Exception):
|
||||||
super(InvalidSyntax, self).__init__(*args, **kwargs)
|
super(InvalidSyntax, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class PluginRequestedUnknownParameters(Flake8Exception):
|
||||||
|
"""The plugin requested unknown parameters."""
|
||||||
|
|
||||||
|
FORMAT = '"%(name)s" requested unknown parameters causing %(exc)s'
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
"""Pop certain keyword arguments for initialization."""
|
||||||
|
self.original_exception = kwargs.pop('exception')
|
||||||
|
self.plugin = kwargs.pop('plugin')
|
||||||
|
super(PluginRequestedUnknownParameters, self).__init__(
|
||||||
|
*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."""
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue