Skip to content

Display exception string when loading a plugin failed #7512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def load_plugins(options: Options,

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

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

try:
module = importlib.import_module(module_name)
except Exception:
plugin_error("Error importing plugin '{}'".format(plugin_path))
except Exception as exc:
plugin_error("Error importing plugin '{}': {}".format(plugin_path, exc))
finally:
if plugin_dir is not None:
assert sys.path[0] == plugin_dir
Expand Down
4 changes: 2 additions & 2 deletions mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,15 @@ def is_errors_for_file(self, file: str) -> bool:
"""Are there any errors for the given file?"""
return file in self.error_info_map

def raise_error(self) -> None:
def raise_error(self, use_stdout: bool = True) -> None:
"""Raise a CompileError with the generated messages.

Render the messages suitable for displaying.
"""
# self.new_messages() will format all messages that haven't already
# been returned from a file_messages() call.
raise CompileError(self.new_messages(),
use_stdout=True,
use_stdout=use_stdout,
module_with_blocker=self.blocker_module())

def format_messages(self, error_info: List[ErrorInfo],
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-custom-plugin.test
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ tmp/mypy.ini:2: error: Can't find plugin 'tmp/missing.py'
[[mypy]
plugins=missing
[out]
tmp/mypy.ini:2: error: Error importing plugin 'missing'
tmp/mypy.ini:2: error: Error importing plugin 'missing': No module named 'missing'

[case testMultipleSectionsDefinePlugin]
# flags: --config-file tmp/mypy.ini
Expand Down