Skip to content

fix(maaend): 脚本设置任务在配置目录缺失时,final_task 仍尝试换入并再报一条「源目录不存在」 #749

Description

@Taimer0721

由 Claude Code 定时任务 Sentry daily triage 自动建立(模型:Opus 5),未经人工复核。
Sentry issue: AUTO-MAS-BACKEND-A0 — https://auto-mas.sentry.io/issues/AUTO-MAS-BACKEND-A0

现象

RuntimeError: 配置换入的源目录不存在: E:\AUTO MAS\MAAEND\MaaEnd-v2.28.0-win-x86_64\config,2 条事件,release auto-mas@v5.5.0-beta.5(dist 56cdbb8c936e,即带 #740 热修的 release 分支),单机。

同一秒还各有一条 AUTO-MAS-BACKEND-7M(FileNotFoundError: 未找到 MaaEnd 配置文件, 请检查 MaaEnd 路径设置或先启动 MaaEnd 完成配置文件生成)——两条是同一次「脚本设置」任务的前后两个报错。

定位

app/task/MaaEnd/ScriptConfig.py 的 final_task()(dev 35b66db86 第 217–218 行):

if self.use_mas_config and self.config_file_path:
    swap_in_dir(self.maaend_set_path, self.config_file_path)

swap_in_dir()(app/utils/io.py)要求 src 必须存在,不存在就抛这个 RuntimeError。

根因

main_task() → set_maaend() 在 MaaEnd 的 config/mxu-MaaEnd.json 不存在时抛 FileNotFoundError(这是用户真正该看到的错误),BaseTask._execute_task 先 on_crash(),随后照常跑 final_task();final_task() 不看 main_task 是否失败、也不看 maaend_set_path 是否存在,直接把一个不存在的目录「换入」MAS 配置目录,于是又抛一次并再 on_crash() 一次。用户收到两条错误通知,第二条与真因无关。

git log -S 显示这段是 #728(2fb7aeb4c,原子换入)改出来的:改之前是 shutil.rmtree(config_file_path) + copytree(maaend_set_path, ...),同样场景会先删掉 MAS 侧配置再报错,比现在更糟;#728 把破坏性去掉了,但没补「主任务失败就别回写」的判断。

同仓其它 ScriptConfig 已有现成写法:app/task/Okww/ScriptConfig.py 的 final_task() 用 if not self.crashed and ... 跳过回写;app/task/OkNte/ScriptConfig.py 在 swap_in_dir 前显式判 script_config_path.exists() 并给出可读文案。MaaEnd 两者都没有。

复现与影响

把 MaaEnd 脚本路径指向一个还没启动过 MaaEnd(没有 config/ 目录)的安装目录,在用户页点「脚本设置」:任务失败,通知里先后出现 未找到 MaaEnd 配置文件… 与 配置换入的源目录不存在… 两条。影响只是误导性的第二条错误;MAS 侧配置不会被破坏(#728 之后)。

建议修复方向

照 Okww 的写法:__init__ 里 self.crashed = False,on_crash() 置 True,final_task() 的回写分支加 not self.crashed,并把 status = "完成" 收进未崩溃分支。改动限于 app/task/MaaEnd/ScriptConfig.py。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Sentry dailySentry daily issuesbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions