mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-30 02:46:52 +00:00
Let's catch exceptions, log them, and re-raise as a FailedToLoad exception. This also refactors the actually loading of plugins into a private method on the Plugin class.
25 lines
796 B
Python
25 lines
796 B
Python
"""Exception classes for all of Flake8."""
|
|
|
|
|
|
class Flake8Exception(Exception):
|
|
"""Plain Flake8 exception."""
|
|
|
|
pass
|
|
|
|
|
|
class FailedToLoadPlugin(Flake8Exception):
|
|
"""Exception raised when a plugin fails to load."""
|
|
|
|
FORMAT = 'Flake8 failed to load plugin "%(name)s" due to %(exc)s.'
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
"""Initialize our FailedToLoadPlugin exception."""
|
|
self.plugin = kwargs.pop('plugin')
|
|
self.ep_name = self.plugin.name
|
|
self.original_exception = kwargs.pop('exception')
|
|
super(FailedToLoadPlugin, self).__init__(*args, **kwargs)
|
|
|
|
def __str__(self):
|
|
"""Return a nice string for our exception."""
|
|
return self.FORMAT % {'name': self.ep_name,
|
|
'exc': self.original_exception}
|