summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2022-01-23 20:44:19 -0500
committerGitHub <noreply@github.com>2022-01-23 20:44:19 -0500
commitf178bd340d32289a3cc7c9fdde356de7f6f23341 (patch)
treefa832a9746c06a10fcf08576ad12e368d1a54f0e
parente704ab4d4405fde784aeecde47f563900f5f8dfd (diff)
parentd2333c4471754355641ca4fa78295dd0dcf6b2f1 (diff)
downloadflake8-main.tar.gz
Merge pull request #1543 from asottile/filename-in-execution-errormain
include the file path in the plugin execution error
-rw-r--r--src/flake8/checker.py4
-rw-r--r--src/flake8/exceptions.py23
-rw-r--r--tests/unit/test_exceptions.py1
-rw-r--r--tests/unit/test_file_checker.py7
4 files changed, 25 insertions, 10 deletions
diff --git a/src/flake8/checker.py b/src/flake8/checker.py
index 2e8117f..28c954c 100644
--- a/src/flake8/checker.py
+++ b/src/flake8/checker.py
@@ -356,7 +356,9 @@ class FileChecker:
exc_info=True,
)
raise exceptions.PluginExecutionFailed(
- plugin_name=plugin.display_name, exception=all_exc
+ filename=self.filename,
+ plugin_name=plugin.display_name,
+ exception=all_exc,
)
@staticmethod
diff --git a/src/flake8/exceptions.py b/src/flake8/exceptions.py
index e2dfd77..8e13cd8 100644
--- a/src/flake8/exceptions.py
+++ b/src/flake8/exceptions.py
@@ -54,17 +54,24 @@ class PluginRequestedUnknownParameters(Flake8Exception):
class PluginExecutionFailed(Flake8Exception):
"""The plugin failed during execution."""
- FORMAT = '"%(name)s" failed during execution due to "%(exc)s"'
-
- def __init__(self, plugin_name: str, exception: Exception) -> None:
+ FORMAT = '{fname}: "{plugin}" failed during execution due to {exc!r}'
+
+ def __init__(
+ self,
+ filename: str,
+ plugin_name: str,
+ exception: Exception,
+ ) -> None:
"""Utilize keyword arguments for message generation."""
+ self.filename = filename
self.plugin_name = plugin_name
self.original_exception = exception
- super().__init__(plugin_name, exception)
+ super().__init__(filename, plugin_name, exception)
def __str__(self) -> str:
"""Format our exception message."""
- return self.FORMAT % {
- "name": self.plugin_name,
- "exc": self.original_exception,
- }
+ return self.FORMAT.format(
+ fname=self.filename,
+ plugin=self.plugin_name,
+ exc=self.original_exception,
+ )
diff --git a/tests/unit/test_exceptions.py b/tests/unit/test_exceptions.py
index 06c5179..96d0244 100644
--- a/tests/unit/test_exceptions.py
+++ b/tests/unit/test_exceptions.py
@@ -18,6 +18,7 @@ from flake8 import exceptions
exception=ValueError("boom!"),
),
exceptions.PluginExecutionFailed(
+ filename="filename.py",
plugin_name="plugin_name",
exception=ValueError("boom!"),
),
diff --git a/tests/unit/test_file_checker.py b/tests/unit/test_file_checker.py
index ee4f745..3fe2e51 100644
--- a/tests/unit/test_file_checker.py
+++ b/tests/unit/test_file_checker.py
@@ -54,5 +54,10 @@ def test_raises_exception_on_failed_plugin(tmp_path, default_options):
plugins=finder.Checkers([], [], []),
options=default_options,
)
- with pytest.raises(flake8.exceptions.PluginExecutionFailed):
+ with pytest.raises(flake8.exceptions.PluginExecutionFailed) as excinfo:
fchecker.run_check(plugin)
+ expected = (
+ f'{fname}: "plugin-name[X]" failed during execution '
+ f"due to ValueError()"
+ )
+ assert str(excinfo.value) == expected