From 753756dfd3fec2108ad5622103d9067b97cca231 Mon Sep 17 00:00:00 2001 From: unknown <2916963017@qq.com> Date: Sun, 22 Feb 2026 22:34:11 +0800 Subject: [PATCH 1/2] feat:add hot reload when failed to load plugins --- astrbot/core/star/star_manager.py | 11 ++++++++++- dashboard/src/views/ExtensionPage.vue | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/astrbot/core/star/star_manager.py b/astrbot/core/star/star_manager.py index 93512bde2..55d7090ab 100644 --- a/astrbot/core/star/star_manager.py +++ b/astrbot/core/star/star_manager.py @@ -529,8 +529,17 @@ async def load( requirements_path=requirements_path, ) except Exception as e: - logger.error(traceback.format_exc()) + error_trace = traceback.format_exc() + logger.error(error_trace) logger.error(f"插件 {root_dir_name} 导入失败。原因:{e!s}") + fail_rec += f"加载 {root_dir_name} 插件时出现问题,原因 {e!s}。\n" + self.failed_plugin_dict[root_dir_name] = { + "error": str(e), + "traceback": error_trace, + } + if path in star_map: + logger.info("失败插件依旧在插件列表中") + star_map.pop(path) continue # 检查 _conf_schema.json diff --git a/dashboard/src/views/ExtensionPage.vue b/dashboard/src/views/ExtensionPage.vue index 9c7245648..74a5558fb 100644 --- a/dashboard/src/views/ExtensionPage.vue +++ b/dashboard/src/views/ExtensionPage.vue @@ -747,12 +747,13 @@ const showPluginInfo = (plugin) => { const reloadPlugin = async (plugin_name) => { try { const res = await axios.post("/api/plugin/reload", { name: plugin_name }); + await getExtensions(); if (res.data.status === "error") { toast(res.data.message, "error"); return; } toast(tm("messages.reloadSuccess"), "success"); - getExtensions(); + //getExtensions(); } catch (err) { toast(err, "error"); } From 35e0273cb3dc575e15e86fb2378f66952df5a831 Mon Sep 17 00:00:00 2001 From: unknown <2916963017@qq.com> Date: Sun, 22 Feb 2026 23:09:31 +0800 Subject: [PATCH 2/2] apply bot suggestions --- astrbot/core/star/star_manager.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/astrbot/core/star/star_manager.py b/astrbot/core/star/star_manager.py index 55d7090ab..5f5157337 100644 --- a/astrbot/core/star/star_manager.py +++ b/astrbot/core/star/star_manager.py @@ -538,8 +538,10 @@ async def load( "traceback": error_trace, } if path in star_map: - logger.info("失败插件依旧在插件列表中") - star_map.pop(path) + logger.info("失败插件依旧在插件列表中,正在清理...") + metadata = star_map.pop(path) + if metadata in star_registry: + star_registry.remove(metadata) continue # 检查 _conf_schema.json @@ -793,6 +795,11 @@ async def load( "traceback": errors, } # 记录注册失败的插件名称,以便后续重载插件 + if path in star_map: + logger.info("失败插件依旧在插件列表中,正在清理...") + metadata = star_map.pop(path) + if metadata in star_registry: + star_registry.remove(metadata) # 清除 pip.main 导致的多余的 logging handlers for handler in logging.root.handlers[:]: