mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 11:42:44 +08:00
feat: 应用层异常处理
This commit is contained in:
parent
3945ac95d1
commit
437971ded8
|
@ -2,6 +2,7 @@ from __future__ import annotations
|
|||
|
||||
import logging
|
||||
import asyncio
|
||||
import traceback
|
||||
|
||||
from ..platform import manager as im_mgr
|
||||
from ..provider.session import sessionmgr as llm_session_mgr
|
||||
|
@ -65,4 +66,12 @@ class Application:
|
|||
asyncio.create_task(self.ctrl.run())
|
||||
]
|
||||
|
||||
await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
|
||||
try:
|
||||
|
||||
await asyncio.wait(tasks)
|
||||
|
||||
except asyncio.CancelledError:
|
||||
self.logger.info("程序退出.")
|
||||
except Exception as e:
|
||||
self.logger.error(f"应用运行致命异常: {e}")
|
||||
self.logger.debug(f"Traceback: {traceback.format_exc()}")
|
||||
|
|
|
@ -61,8 +61,9 @@ class Controller:
|
|||
|
||||
asyncio.create_task(_process_query(selected_query))
|
||||
except Exception as e:
|
||||
self.ap.logger.error(f"事件处理循环出错: {e}")
|
||||
traceback.print_exc()
|
||||
# traceback.print_exc()
|
||||
self.ap.logger.error(f"控制器循环出错: {e}")
|
||||
self.ap.logger.debug(f"Traceback: {traceback.format_exc()}")
|
||||
|
||||
async def _check_output(self, result: pipeline_entities.StageProcessResult):
|
||||
"""检查输出
|
||||
|
@ -144,7 +145,7 @@ class Controller:
|
|||
await self._execute_from_stage(0, query)
|
||||
except Exception as e:
|
||||
self.ap.logger.error(f"处理请求时出错 {query}: {e}")
|
||||
traceback.print_exc()
|
||||
self.ap.logger.debug(f"处理请求时出错 {query}: {e}", exc_info=True)
|
||||
finally:
|
||||
self.ap.logger.debug(f"Query {query} processed")
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import json
|
|||
import os
|
||||
import logging
|
||||
import asyncio
|
||||
import traceback
|
||||
|
||||
from mirai import At, GroupMessage, MessageEvent, StrangerMessage, \
|
||||
FriendMessage, Image, MessageChain, Plain
|
||||
|
@ -150,4 +151,8 @@ class QQBotManager:
|
|||
)
|
||||
|
||||
async def run(self):
|
||||
await self.adapter.run_async()
|
||||
try:
|
||||
await self.adapter.run_async()
|
||||
except Exception as e:
|
||||
self.ap.logger.error('平台适配器运行出错: ' + str(e))
|
||||
self.ap.logger.debug(f"Traceback: {traceback.format_exc()}")
|
||||
|
|
Loading…
Reference in New Issue
Block a user