Skip to content

Commit ecaec41

Browse files
authored
feat: add hot reload when failed to load plugins (#5334)
* feat:add hot reload when failed to load plugins * apply bot suggestions
1 parent 997b511 commit ecaec41

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

astrbot/core/star/star_manager.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,19 @@ async def load(
529529
requirements_path=requirements_path,
530530
)
531531
except Exception as e:
532-
logger.error(traceback.format_exc())
532+
error_trace = traceback.format_exc()
533+
logger.error(error_trace)
533534
logger.error(f"插件 {root_dir_name} 导入失败。原因:{e!s}")
535+
fail_rec += f"加载 {root_dir_name} 插件时出现问题,原因 {e!s}\n"
536+
self.failed_plugin_dict[root_dir_name] = {
537+
"error": str(e),
538+
"traceback": error_trace,
539+
}
540+
if path in star_map:
541+
logger.info("失败插件依旧在插件列表中,正在清理...")
542+
metadata = star_map.pop(path)
543+
if metadata in star_registry:
544+
star_registry.remove(metadata)
534545
continue
535546

536547
# 检查 _conf_schema.json
@@ -784,6 +795,11 @@ async def load(
784795
"traceback": errors,
785796
}
786797
# 记录注册失败的插件名称,以便后续重载插件
798+
if path in star_map:
799+
logger.info("失败插件依旧在插件列表中,正在清理...")
800+
metadata = star_map.pop(path)
801+
if metadata in star_registry:
802+
star_registry.remove(metadata)
787803

788804
# 清除 pip.main 导致的多余的 logging handlers
789805
for handler in logging.root.handlers[:]:

dashboard/src/views/ExtensionPage.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,12 +747,13 @@ const showPluginInfo = (plugin) => {
747747
const reloadPlugin = async (plugin_name) => {
748748
try {
749749
const res = await axios.post("/api/plugin/reload", { name: plugin_name });
750+
await getExtensions();
750751
if (res.data.status === "error") {
751752
toast(res.data.message, "error");
752753
return;
753754
}
754755
toast(tm("messages.reloadSuccess"), "success");
755-
getExtensions();
756+
//getExtensions();
756757
} catch (err) {
757758
toast(err, "error");
758759
}

0 commit comments

Comments
 (0)