mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-10 23:04:18 +00:00
include the file path in the plugin execution error
This commit is contained in:
parent
9de288a22f
commit
d2333c4471
4 changed files with 24 additions and 9 deletions
|
|
@ -356,7 +356,9 @@ class FileChecker:
|
||||||
exc_info=True,
|
exc_info=True,
|
||||||
)
|
)
|
||||||
raise exceptions.PluginExecutionFailed(
|
raise exceptions.PluginExecutionFailed(
|
||||||
plugin_name=plugin.display_name, exception=all_exc
|
filename=self.filename,
|
||||||
|
plugin_name=plugin.display_name,
|
||||||
|
exception=all_exc,
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
||||||
|
|
@ -54,17 +54,24 @@ class PluginRequestedUnknownParameters(Flake8Exception):
|
||||||
class PluginExecutionFailed(Flake8Exception):
|
class PluginExecutionFailed(Flake8Exception):
|
||||||
"""The plugin failed during execution."""
|
"""The plugin failed during execution."""
|
||||||
|
|
||||||
FORMAT = '"%(name)s" failed during execution due to "%(exc)s"'
|
FORMAT = '{fname}: "{plugin}" failed during execution due to {exc!r}'
|
||||||
|
|
||||||
def __init__(self, plugin_name: str, exception: Exception) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
filename: str,
|
||||||
|
plugin_name: str,
|
||||||
|
exception: Exception,
|
||||||
|
) -> None:
|
||||||
"""Utilize keyword arguments for message generation."""
|
"""Utilize keyword arguments for message generation."""
|
||||||
|
self.filename = filename
|
||||||
self.plugin_name = plugin_name
|
self.plugin_name = plugin_name
|
||||||
self.original_exception = exception
|
self.original_exception = exception
|
||||||
super().__init__(plugin_name, exception)
|
super().__init__(filename, plugin_name, exception)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
"""Format our exception message."""
|
"""Format our exception message."""
|
||||||
return self.FORMAT % {
|
return self.FORMAT.format(
|
||||||
"name": self.plugin_name,
|
fname=self.filename,
|
||||||
"exc": self.original_exception,
|
plugin=self.plugin_name,
|
||||||
}
|
exc=self.original_exception,
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ from flake8 import exceptions
|
||||||
exception=ValueError("boom!"),
|
exception=ValueError("boom!"),
|
||||||
),
|
),
|
||||||
exceptions.PluginExecutionFailed(
|
exceptions.PluginExecutionFailed(
|
||||||
|
filename="filename.py",
|
||||||
plugin_name="plugin_name",
|
plugin_name="plugin_name",
|
||||||
exception=ValueError("boom!"),
|
exception=ValueError("boom!"),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -54,5 +54,10 @@ def test_raises_exception_on_failed_plugin(tmp_path, default_options):
|
||||||
plugins=finder.Checkers([], [], []),
|
plugins=finder.Checkers([], [], []),
|
||||||
options=default_options,
|
options=default_options,
|
||||||
)
|
)
|
||||||
with pytest.raises(flake8.exceptions.PluginExecutionFailed):
|
with pytest.raises(flake8.exceptions.PluginExecutionFailed) as excinfo:
|
||||||
fchecker.run_check(plugin)
|
fchecker.run_check(plugin)
|
||||||
|
expected = (
|
||||||
|
f'{fname}: "plugin-name[X]" failed during execution '
|
||||||
|
f"due to ValueError()"
|
||||||
|
)
|
||||||
|
assert str(excinfo.value) == expected
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue