调整异常扣分记录,如果是异常的数据,则不扣分
This commit is contained in:
@@ -61,7 +61,7 @@ def plugin_stats_decorator(plugin_name: str) -> Callable:
|
||||
logger.debug(f"[{plugin_name}] 记录插件调用统计")
|
||||
stats_db.record_plugin_call(
|
||||
plugin_name=plugin_name,
|
||||
command=command, # 使用提取的指令而不是完整内容
|
||||
command=command,
|
||||
user_id=sender,
|
||||
group_id=roomid,
|
||||
success=success,
|
||||
@@ -69,6 +69,30 @@ def plugin_stats_decorator(plugin_name: str) -> Callable:
|
||||
)
|
||||
logger.info(f"[{plugin_name}] 成功记录插件调用: {command}, 耗时: {process_time_ms:.2f}ms")
|
||||
|
||||
# 定义不需要记录错误的正常业务状态
|
||||
normal_responses = {
|
||||
"没有权限",
|
||||
"命令格式错误",
|
||||
"请先开启功能",
|
||||
# 可以添加其他正常的业务状态返回
|
||||
}
|
||||
|
||||
# 新增:如果业务代码返回失败,且不属于正常业务状态,则记录错误信息
|
||||
if not success and response and response not in normal_responses:
|
||||
logger.debug(f"[{plugin_name}] 业务代码返回失败,记录错误信息: {response}")
|
||||
try:
|
||||
stats_db.record_error(
|
||||
plugin_name=plugin_name,
|
||||
command=command,
|
||||
user_id=sender,
|
||||
group_id=roomid,
|
||||
error_message=f"业务返回失败: {response}",
|
||||
stack_trace="业务代码捕获的错误,无堆栈信息"
|
||||
)
|
||||
logger.info(f"[{plugin_name}] 成功记录业务失败信息: {response}")
|
||||
except Exception as err_record_error:
|
||||
logger.error(f"[{plugin_name}] 记录业务失败信息出错: {err_record_error}")
|
||||
|
||||
return success, response
|
||||
except Exception as e:
|
||||
# 计算执行时间(毫秒)
|
||||
@@ -100,12 +124,13 @@ def plugin_stats_decorator(plugin_name: str) -> Callable:
|
||||
command=command, # 使用提取的指令而不是完整内容
|
||||
user_id=sender,
|
||||
group_id=roomid,
|
||||
error_message=error_message,
|
||||
stack_trace=stack_trace
|
||||
error_message=error_message[:500] if error_message else "未知错误", # 限制长度并确保不为空
|
||||
stack_trace=stack_trace[:2000] if stack_trace else "无堆栈信息" # 限制长度并确保不为空
|
||||
)
|
||||
logger.info(f"[{plugin_name}] 成功记录插件错误: {command}, 错误: {error_message}")
|
||||
except Exception as db_error:
|
||||
logger.error(f"[{plugin_name}] 记录插件统计数据失败: {db_error}")
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
# 重新抛出异常,让上层处理
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user