Skip to content

Commit 2094639

Browse files
blueyedmsullivan
authored andcommitted
Display exception string when loading a plugin failed (#7512)
This helps with seeing what the issue is (e.g. with django-stubs [1]). 1: typeddjango/django-stubs#160
1 parent e6e6c0f commit 2094639

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

mypy/build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def load_plugins(options: Options,
352352

353353
def plugin_error(message: str) -> None:
354354
errors.report(line, 0, message)
355-
errors.raise_error()
355+
errors.raise_error(use_stdout=False)
356356

357357
custom_plugins = [] # type: List[Plugin]
358358
errors.set_file(options.config_file, None)
@@ -381,8 +381,8 @@ def plugin_error(message: str) -> None:
381381

382382
try:
383383
module = importlib.import_module(module_name)
384-
except Exception:
385-
plugin_error("Error importing plugin '{}'".format(plugin_path))
384+
except Exception as exc:
385+
plugin_error("Error importing plugin '{}': {}".format(plugin_path, exc))
386386
finally:
387387
if plugin_dir is not None:
388388
assert sys.path[0] == plugin_dir

mypy/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,15 @@ def is_errors_for_file(self, file: str) -> bool:
399399
"""Are there any errors for the given file?"""
400400
return file in self.error_info_map
401401

402-
def raise_error(self) -> None:
402+
def raise_error(self, use_stdout: bool = True) -> None:
403403
"""Raise a CompileError with the generated messages.
404404
405405
Render the messages suitable for displaying.
406406
"""
407407
# self.new_messages() will format all messages that haven't already
408408
# been returned from a file_messages() call.
409409
raise CompileError(self.new_messages(),
410-
use_stdout=True,
410+
use_stdout=use_stdout,
411411
module_with_blocker=self.blocker_module())
412412

413413
def format_messages(self, error_info: List[ErrorInfo],

test-data/unit/check-custom-plugin.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ tmp/mypy.ini:2: error: Can't find plugin 'tmp/missing.py'
7070
\[mypy]
7171
plugins=missing
7272
[out]
73-
tmp/mypy.ini:2: error: Error importing plugin 'missing'
73+
tmp/mypy.ini:2: error: Error importing plugin 'missing': No module named 'missing'
7474

7575
[case testMultipleSectionsDefinePlugin]
7676
# flags: --config-file tmp/mypy.ini

0 commit comments

Comments
 (0)