babalae/better-genshin-impact · error · FileNotFoundException
JSON 战斗策略文件不存在
Error message
JSON 战斗策略文件不存在
What it means
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.
Source
Thrown at BetterGenshinImpact/GameTask/AutoFight/Script/JsonCombatStrategyParser.cs:28
/// <summary>
/// JSON 战斗策略解析器
/// </summary>
public static class JsonCombatStrategyParser
{
/// <summary>
/// 从文件解析 JSON 战斗策略
/// </summary>
/// <param name="path">策略文件路径</param>
/// <returns>解析后的战斗策略</returns>
/// <exception cref="FileNotFoundException">文件不存在</exception>
/// <exception cref="InvalidOperationException">解析失败或格式错误</exception>
public static JsonCombatStrategy ParseFile(string path)
{
if (!File.Exists(path))
{
Logger.LogError("JSON 战斗策略文件不存在:{Path}", path);
throw new FileNotFoundException("JSON 战斗策略文件不存在", path);
}
var json = File.ReadAllText(path);
return Parse(json);
}
/// <summary>
/// 从 JSON 字符串解析战斗策略
/// </summary>
/// <param name="json">JSON 字符串</param>
/// <returns>解析后的战斗策略</returns>
/// <exception cref="InvalidOperationException">解析失败或格式错误</exception>
public static JsonCombatStrategy Parse(string json)
{
JsonCombatStrategy? strategy;
try
{
strategy = JsonConvert.DeserializeObject<JsonCombatStrategy>(json);View on GitHub (pinned to a7cb36712d)
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.
Example fix
// before
var strategy = JsonCombatStrategyParser.ParseFile(relativePath);
// after
var fullPath = Path.GetFullPath(relativePath);
if (!File.Exists(fullPath))
throw new FileNotFoundException($"策略文件不存在: {fullPath}");
var strategy = JsonCombatStrategyParser.ParseFile(fullPath); Defensive patterns
Strategy: validation
Validate before calling
// Validate file existence before parsing
var fullPath = Path.GetFullPath(strategyPath);
if (!File.Exists(fullPath))
{
Console.Error.WriteLine($"策略文件不存在: {fullPath}");
return;
}
var strategy = JsonCombatStrategyParser.ParseFile(fullPath); Try / catch
try
{
var strategy = JsonCombatStrategyParser.ParseFile(path);
}
catch (FileNotFoundException e)
{
Logger.LogError("找不到策略文件: {FileName}", e.FileName);
// Prompt user to select a valid file or check the path
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 未找到{featName}的素材文件夹
- 等待 {targetDescription} 超时({timeout}ms)
- 识别元素在 {actualTimeout}ms 后超时未消失!
- AutoSkip的配置参数需要为AutoSkipConfig类型
- 从 library 字段读取路径 '{path}' 失败: {ex.Message}
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/3bb10aaeedc5aff5.
Report an issue: GitHub.