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)