babalae/better-genshin-impact · error · Exception

路径文件解析失败:{fileName}

Error message

路径文件解析失败:{fileName}

What it means

RunPathingFile 用 PathingTask.BuildFromFilePath 解析资产目录下的寻路 JSON,返回 null 即抛 Exception,表示文件存在但内容无法解析为有效 PathingTask(格式错误或 schema 不匹配)。

Source

Thrown at BetterGenshinImpact/GameTask/AutoBoss/AutoBossTask.cs:1118

        _logger.LogInformation("{Name}:前往 {Boss}", Name, _taskParam.BossName);
        if (AutoBossData.IsNoPathingSupportBoss(_taskParam.BossName))
        {
            await RunPathingFile($"{_taskParam.BossName}强制传送.json");
            await RunKeyMouseFile($"{_taskParam.BossName}键鼠前往.json");
            return;
        }

        await RunPathingFile($"{_taskParam.BossName}前往.json");
    }

    /// <summary>
    /// 加载并执行 AutoBoss 资产目录中的寻路 JSON 文件。
    /// </summary>
    /// <param name="fileName">路线文件名。</param>
    private async Task RunPathingFile(string fileName)
    {
        await _returnMainUiTask.Start(_ct);
        var task = PathingTask.BuildFromFilePath(BuildPathingAssetPath(fileName)) ?? throw new Exception($"路径文件解析失败:{fileName}");
        await RunPathingTask(task);
    }

    /// <summary>
    /// 使用自动首领讨伐的队伍配置执行寻路任务。
    /// </summary>
    /// <param name="task">已经解析好的寻路任务。</param>
    private async Task RunPathingTask(PathingTask task)
    {
        var executor = new PathExecutor(_ct)
        {
            PartyConfig = BuildPathingPartyConfig()
        };
        await executor.Pathing(task);
    }

    /// <summary>
    /// 构建首领路线执行时使用的队伍配置,禁止寻路过程自动切队和自动战斗。

View on GitHub (pinned to a7cb36712d)

Solutions

  1. 用 JSON 校验工具检查报错文件名对应文件的语法。
  2. 对照当前 PathingTask 的 schema/示例路线文件修正字段。
  3. 重新获取/恢复与程序版本匹配的路线文件。
  4. 查看 BuildFromFilePath 内部日志定位具体解析失败字段。

Example fix

// before
var task = PathingTask.BuildFromFilePath(BuildPathingAssetPath(fileName)) ?? throw new Exception($"路径文件解析失败:{fileName}");

// after
var path = BuildPathingAssetPath(fileName);
var task = PathingTask.BuildFromFilePath(path);
if (task == null)
{
    throw new Exception($"路径文件解析失败:{fileName}(路径={path}),请检查 JSON 格式与字段");
}
Defensive patterns

Strategy: validation

Validate before calling

var path = BuildPathingAssetPath(fileName);
if (!File.Exists(path)) throw new FileNotFoundException(path);
// 进一步:尝试 JsonDocument.Parse 预校验语法
var json = File.ReadAllText(path);
using (JsonDocument.Parse(json)) { }

Prevention

When it happens

Trigger: JSON 语法错误(缺括号、尾逗号);schema 字段缺失或类型不符;文件编码异常(BOM/UTF-8 误判);文件被截断或为空;路线文件版本与当前 PathingTask 模型不兼容。

Common situations: 用户手动编辑路线文件出错;资产文件随版本更新 schema 变化但文件未更新;第三方路线文件格式不兼容;下载/复制不完整。

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/e828c0f020b65ef7. Report an issue: GitHub.