From 9052214e6d545793a496eddfeb7bf73d9da968e7 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Wed, 21 Apr 2021 18:26:58 +0800 Subject: [PATCH] :wheelchair: raise ImportError when exec_module --- nonebot/plugin/manager.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nonebot/plugin/manager.py b/nonebot/plugin/manager.py index d46f6f6e..f4121900 100644 --- a/nonebot/plugin/manager.py +++ b/nonebot/plugin/manager.py @@ -221,7 +221,11 @@ class PluginLoader(SourceFileLoader): if self._export_token: setattr(module, "__export__", _export.get()) - super().exec_module(module) + try: + super().exec_module(module) + except Exception as e: + raise ImportError( + f"Error when executing module {self.name}.") from e if self._plugin_token: _current_plugin.reset(self._plugin_token)