From 477df2dccc15f2763490cf55fa51dabf5bd8143b Mon Sep 17 00:00:00 2001 From: Kyomotoi <0w0@imki.moe> Date: Tue, 9 May 2023 16:54:34 +0800 Subject: =?UTF-8?q?=F0=9F=8E=A8=20=E4=BC=98=E5=8C=96=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ATRI/exceptions.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ATRI/exceptions.py b/ATRI/exceptions.py index 4504b07..bc09ce6 100644 --- a/ATRI/exceptions.py +++ b/ATRI/exceptions.py @@ -40,9 +40,9 @@ def _save_error(prompt: str, content: str) -> str: return track_id -def load_error(track_id: str) -> dict: +def load_error(track_id: str) -> ErrorInfo: path = ERROR_DIR / f"{track_id}.json" - return json.loads(path.read_bytes()) + return ErrorInfo.parse_file(path) class BaseBotException(Exception): @@ -111,10 +111,12 @@ async def _(bot: Bot, event, matcher: Matcher, exception: Optional[Exception]): return try: - raise exception + prompt = exception.__class__.__name__ + track_id = _save_error(prompt, format_exc()) + log.warning(f"Ignore Exception: {prompt}") except BaseBotException as err: prompt = err.prompt or err.__class__.__name__ - track_id = err.track_id + track_id = _save_error(prompt, format_exc()) log.warning(f"BotException: {prompt}") except ActionFailed as err: prompt = "请参考协议端输出" -- cgit v1.2.3