fix: 主要核心后端添加报错捕获机制
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# AUTO-MAS: A Multi-Script, Multi-Config Management and Automation Software
|
||||
# Copyright © 2024-2025 DLmaster361
|
||||
# Copyright © 2025 MoeSnowyFox
|
||||
# Copyright © 2025 AUTO-MAS Team
|
||||
|
||||
# This file is part of AUTO-MAS.
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# AUTO-MAS: A Multi-Script, Multi-Config Management and Automation Software
|
||||
# Copyright © 2024-2025 DLmaster361
|
||||
# Copyright © 2025 AUTO-MAS Team
|
||||
|
||||
# This file is part of AUTO-MAS.
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# AUTO-MAS: A Multi-Script, Multi-Config Management and Automation Software
|
||||
# Copyright © 2024-2025 DLmaster361
|
||||
# Copyright © 2025 MoeSnowyFox
|
||||
# Copyright © 2025 AUTO-MAS Team
|
||||
|
||||
# This file is part of AUTO-MAS.
|
||||
|
||||
@@ -974,27 +975,23 @@ class AppConfig(GlobalConfig):
|
||||
logger.warning("Git仓库不可用,返回默认版本信息")
|
||||
return False, "unknown", "unknown"
|
||||
|
||||
try:
|
||||
# 获取当前 commit
|
||||
current_commit = self.repo.head.commit
|
||||
# 获取当前 commit
|
||||
current_commit = self.repo.head.commit
|
||||
|
||||
# 获取 commit 哈希
|
||||
commit_hash = current_commit.hexsha
|
||||
# 获取 commit 哈希
|
||||
commit_hash = current_commit.hexsha
|
||||
|
||||
# 获取 commit 时间
|
||||
commit_time = datetime.fromtimestamp(current_commit.committed_date)
|
||||
# 获取 commit 时间
|
||||
commit_time = datetime.fromtimestamp(current_commit.committed_date)
|
||||
|
||||
# 检查是否为最新 commit
|
||||
# 获取远程分支的最新 commit
|
||||
origin = self.repo.remotes.origin
|
||||
origin.fetch() # 拉取最新信息
|
||||
remote_commit = self.repo.commit(f"origin/{self.repo.active_branch.name}")
|
||||
is_latest = bool(current_commit.hexsha == remote_commit.hexsha)
|
||||
# 检查是否为最新 commit
|
||||
# 获取远程分支的最新 commit
|
||||
origin = self.repo.remotes.origin
|
||||
origin.fetch() # 拉取最新信息
|
||||
remote_commit = self.repo.commit(f"origin/{self.repo.active_branch.name}")
|
||||
is_latest = bool(current_commit.hexsha == remote_commit.hexsha)
|
||||
|
||||
return is_latest, commit_hash, commit_time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
except Exception as e:
|
||||
logger.warning(f"获取Git版本信息失败: {e}")
|
||||
return False, "error", "error"
|
||||
return is_latest, commit_hash, commit_time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
async def add_script(
|
||||
self, script: Literal["MAA", "General"]
|
||||
@@ -1864,7 +1861,7 @@ class AppConfig(GlobalConfig):
|
||||
async def get_script_combox(self):
|
||||
"""获取脚本下拉框信息"""
|
||||
|
||||
logger.info("Getting script combo box information...")
|
||||
logger.info("开始获取脚本下拉框信息")
|
||||
data = [{"label": "未选择", "value": "-"}]
|
||||
for uid, script in self.ScriptConfig.items():
|
||||
data.append(
|
||||
@@ -1873,7 +1870,7 @@ class AppConfig(GlobalConfig):
|
||||
"value": str(uid),
|
||||
}
|
||||
)
|
||||
logger.success("Script combo box information retrieved successfully.")
|
||||
logger.success("脚本下拉框信息获取成功")
|
||||
|
||||
return data
|
||||
|
||||
@@ -2040,7 +2037,10 @@ class AppConfig(GlobalConfig):
|
||||
data["sanity"] = int(sanity_match.group(1))
|
||||
|
||||
# 提取理智回满时间:理智将在 2025-09-26 18:57 回满。(17h 29m 后)
|
||||
sanity_full_match = re.search(r"(理智将在\s*\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}\s*回满。\(\d+h\s+\d+m\s+后\))", log_line)
|
||||
sanity_full_match = re.search(
|
||||
r"(理智将在\s*\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}\s*回满。\(\d+h\s+\d+m\s+后\))",
|
||||
log_line,
|
||||
)
|
||||
if sanity_full_match:
|
||||
data["sanity_full_at"] = sanity_full_match.group(1)
|
||||
|
||||
@@ -2150,11 +2150,11 @@ class AppConfig(GlobalConfig):
|
||||
|
||||
# 保存日志
|
||||
log_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with log_path.open("w", encoding="utf-8") as f:
|
||||
f.writelines(logs)
|
||||
log_path.write_text("\n".join(logs), encoding="utf-8")
|
||||
# 保存统计数据
|
||||
with log_path.with_suffix(".json").open("w", encoding="utf-8") as f:
|
||||
json.dump(data, f, ensure_ascii=False, indent=4)
|
||||
log_path.with_suffix(".json").write_text(
|
||||
json.dumps(data, ensure_ascii=False, index=4), encoding="utf-8"
|
||||
)
|
||||
|
||||
logger.success(f"MAA 日志统计完成, 日志路径: {log_path}")
|
||||
|
||||
@@ -2179,10 +2179,10 @@ class AppConfig(GlobalConfig):
|
||||
|
||||
# 保存日志
|
||||
log_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with log_path.with_suffix(".log").open("w", encoding="utf-8") as f:
|
||||
f.writelines(logs)
|
||||
with log_path.with_suffix(".json").open("w", encoding="utf-8") as f:
|
||||
json.dump(data, f, ensure_ascii=False, indent=4)
|
||||
log_path.with_suffix(".log").write_text("\n".join(logs), encoding="utf-8")
|
||||
log_path.with_suffix(".json").write_text(
|
||||
json.dumps(data, ensure_ascii=False, indent=4), encoding="utf-8"
|
||||
)
|
||||
|
||||
logger.success(f"通用日志统计完成, 日志路径: {log_path.with_suffix('.log')}")
|
||||
|
||||
@@ -2200,8 +2200,13 @@ class AppConfig(GlobalConfig):
|
||||
|
||||
for json_file in statistic_path_list:
|
||||
|
||||
with json_file.open("r", encoding="utf-8") as f:
|
||||
single_data = json.load(f)
|
||||
try:
|
||||
single_data = json.loads(json_file.read_text(encoding="utf-8"))
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"无法解析文件 {json_file}, 错误信息: {type(e).__name__}: {str(e)}"
|
||||
)
|
||||
continue
|
||||
|
||||
for key in single_data.keys():
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# AUTO-MAS: A Multi-Script, Multi-Config Management and Automation Software
|
||||
# Copyright © 2024-2025 DLmaster361
|
||||
# Copyright © 2025 AUTO-MAS Team
|
||||
|
||||
# This file is part of AUTO-MAS.
|
||||
|
||||
@@ -92,7 +93,7 @@ class _TaskManager:
|
||||
|
||||
return task_id
|
||||
|
||||
# @logger.catch
|
||||
@logger.catch
|
||||
async def run_task(
|
||||
self, mode: str, task_id: uuid.UUID, actual_id: Optional[uuid.UUID]
|
||||
):
|
||||
@@ -124,7 +125,17 @@ class _TaskManager:
|
||||
lambda t: asyncio.create_task(task_item.final_task(t))
|
||||
)
|
||||
self.task_dict[uid].add_done_callback(partial(self.task_dict.pop, uid))
|
||||
await self.task_dict[uid]
|
||||
try:
|
||||
await self.task_dict[uid]
|
||||
except Exception as e:
|
||||
logger.error(f"任务 {task_id} 运行出错: {type(e).__name__}: {str(e)}")
|
||||
await Config.send_json(
|
||||
WebSocketMessage(
|
||||
id=str(task_id),
|
||||
type="Info",
|
||||
data={"Error": f"任务运行时出错 {type(e).__name__}: {str(e)}"},
|
||||
).model_dump()
|
||||
)
|
||||
|
||||
else:
|
||||
|
||||
@@ -262,8 +273,23 @@ class _TaskManager:
|
||||
self.task_dict[script_id].add_done_callback(
|
||||
partial(self.task_dict.pop, script_id)
|
||||
)
|
||||
await self.task_dict[script_id]
|
||||
task["status"] = "完成"
|
||||
try:
|
||||
await self.task_dict[script_id]
|
||||
task["status"] = "完成"
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"任务 {script_id} 运行出错: {type(e).__name__}: {str(e)}"
|
||||
)
|
||||
await Config.send_json(
|
||||
WebSocketMessage(
|
||||
id=str(task_id),
|
||||
type="Info",
|
||||
data={
|
||||
"Error": f"任务运行时出错 {type(e).__name__}: {str(e)}"
|
||||
},
|
||||
).model_dump()
|
||||
)
|
||||
task["status"] = "异常"
|
||||
await Config.send_json(
|
||||
WebSocketMessage(
|
||||
id=str(task_id),
|
||||
@@ -287,7 +313,7 @@ class _TaskManager:
|
||||
else:
|
||||
uid = uuid.UUID(task_id)
|
||||
if uid not in self.task_dict:
|
||||
raise ValueError(f"任务 {uid} 未在运行")
|
||||
raise ValueError("任务未在运行")
|
||||
self.task_dict[uid].cancel()
|
||||
|
||||
async def remove_task(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# AUTO-MAS: A Multi-Script, Multi-Config Management and Automation Software
|
||||
# Copyright © 2024-2025 DLmaster361
|
||||
# Copyright © 2025 AUTO-MAS Team
|
||||
|
||||
# This file is part of AUTO-MAS.
|
||||
|
||||
@@ -108,6 +109,7 @@ class _MainTimer:
|
||||
).model_dump()
|
||||
)
|
||||
|
||||
@logger.catch()
|
||||
async def set_silence(self):
|
||||
"""静默模式通过模拟老板键来隐藏模拟器窗口"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user