From 200559a5808ce16c5954dd19c5ec3374ad148527 Mon Sep 17 00:00:00 2001 From: Lishiling Date: Wed, 18 Mar 2026 23:05:40 +0800 Subject: [PATCH] fix(runtime): avoid creating Star instance in on_error fallback --- src/astrbot_sdk/runtime/handler_dispatcher.py | 2 +- src/astrbot_sdk/star.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/astrbot_sdk/runtime/handler_dispatcher.py b/src/astrbot_sdk/runtime/handler_dispatcher.py index 88d824615..d9c054cca 100644 --- a/src/astrbot_sdk/runtime/handler_dispatcher.py +++ b/src/astrbot_sdk/runtime/handler_dispatcher.py @@ -884,7 +884,7 @@ class HandlerDispatcher: if inspect.isawaitable(result): await result return - await Star().on_error(exc, event, ctx) + await Star.default_on_error(exc, event, ctx) __all__ = ["CapabilityDispatcher", "HandlerDispatcher"] diff --git a/src/astrbot_sdk/star.py b/src/astrbot_sdk/star.py index aef7eb09e..1c5a2ef7f 100644 --- a/src/astrbot_sdk/star.py +++ b/src/astrbot_sdk/star.py @@ -102,7 +102,9 @@ class Star(PluginKVStoreMixin): options=options, ) - async def on_error(self, error: Exception, event, ctx) -> None: + @staticmethod + async def default_on_error(error: Exception, event, ctx) -> None: + del ctx if isinstance(error, AstrBotError): lines: list[str] = [] if error.retryable: @@ -122,6 +124,9 @@ class Star(PluginKVStoreMixin): await event.reply("出了点问题,请联系插件作者") logger.error("handler 执行失败\n{}", traceback.format_exc()) + async def on_error(self, error: Exception, event, ctx) -> None: + await self.default_on_error(error, event, ctx) + @classmethod def __astrbot_is_new_star__(cls) -> bool: return True