{"record":{"id":"3bb10aaeedc5aff5","repo":"babalae/better-genshin-impact","slug":"json-3bb10a","errorCode":null,"errorMessage":"JSON 战斗策略文件不存在","messagePattern":"JSON 战斗策略文件不存在","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/GameTask/AutoFight/Script/JsonCombatStrategyParser.cs","lineNumber":28,"sourceCode":"\n/// <summary>\n/// JSON 战斗策略解析器\n/// </summary>\npublic static class JsonCombatStrategyParser\n{\n    /// <summary>\n    /// 从文件解析 JSON 战斗策略\n    /// </summary>\n    /// <param name=\"path\">策略文件路径</param>\n    /// <returns>解析后的战斗策略</returns>\n    /// <exception cref=\"FileNotFoundException\">文件不存在</exception>\n    /// <exception cref=\"InvalidOperationException\">解析失败或格式错误</exception>\n    public static JsonCombatStrategy ParseFile(string path)\n    {\n        if (!File.Exists(path))\n        {\n            Logger.LogError(\"JSON 战斗策略文件不存在：{Path}\", path);\n            throw new FileNotFoundException(\"JSON 战斗策略文件不存在\", path);\n        }\n\n        var json = File.ReadAllText(path);\n        return Parse(json);\n    }\n\n    /// <summary>\n    /// 从 JSON 字符串解析战斗策略\n    /// </summary>\n    /// <param name=\"json\">JSON 字符串</param>\n    /// <returns>解析后的战斗策略</returns>\n    /// <exception cref=\"InvalidOperationException\">解析失败或格式错误</exception>\n    public static JsonCombatStrategy Parse(string json)\n    {\n        JsonCombatStrategy? strategy;\n        try\n        {\n            strategy = JsonConvert.DeserializeObject<JsonCombatStrategy>(json);","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/AutoFight/Script/JsonCombatStrategyParser.cs#L10-L46","documentation":"Thrown by JsonCombatStrategyParser.ParseFile when File.Exists(path) returns false. The JSON strategy file path provided does not point to an existing file on disk. This is a FileNotFoundException with the path as the fileName parameter.","triggerScenarios":"Calling JsonCombatStrategyParser.ParseFile with a path that does not exist, a relative path resolved from the wrong working directory, or a path with a typo in the filename or directory.","commonSituations":"User configures a custom JSON strategy path that is wrong, moved, or deleted. Also occurs when the path is relative and the application's working directory differs from what the user expected, or when Windows/Linux path separators are mixed.","solutions":["Verify the file exists at the exact path provided (check for typos, case sensitivity on Linux).","Use an absolute path to avoid working-directory ambiguity.","Check that the application has read permissions on the file.","Log or print the resolved path before calling ParseFile to confirm what path is actually being used."],"exampleFix":"// before\nvar strategy = JsonCombatStrategyParser.ParseFile(relativePath);\n\n// after\nvar fullPath = Path.GetFullPath(relativePath);\nif (!File.Exists(fullPath))\n    throw new FileNotFoundException($\"策略文件不存在: {fullPath}\");\nvar strategy = JsonCombatStrategyParser.ParseFile(fullPath);","handlingStrategy":"validation","validationCode":"// Validate file existence before parsing\nvar fullPath = Path.GetFullPath(strategyPath);\nif (!File.Exists(fullPath))\n{\n    Console.Error.WriteLine($\"策略文件不存在: {fullPath}\");\n    return;\n}\nvar strategy = JsonCombatStrategyParser.ParseFile(fullPath);","typeGuard":null,"tryCatchPattern":"try\n{\n    var strategy = JsonCombatStrategyParser.ParseFile(path);\n}\ncatch (FileNotFoundException e)\n{\n    Logger.LogError(\"找不到策略文件: {FileName}\", e.FileName);\n    // Prompt user to select a valid file or check the path\n}","preventionTips":["Always use absolute paths for strategy files to avoid working-directory ambiguity.","Validate file existence with File.Exists before calling ParseFile.","Log the resolved path (Path.GetFullPath) to debug path issues.","On Linux, remember file paths are case-sensitive."],"tags":["json-strategy","file-not-found","io","configuration"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}