babalae/better-genshin-impact · error · Exception

地脉花策略配置缺失

Error message

地脉花策略配置缺失

What it means

Thrown by ExecuteMatchingStrategy when _configData is null or _configData.LeyLinePositions is null. ExecuteMatchingStrategy is called after FindLeyLineOutcropByBook/FindLeyLineOutcrop to match the detected ley line coordinates against known positions and select a strategy. If the config was never loaded (LoadConfigData failed silently or _configData was not populated) or the loaded config lacks the LeyLinePositions dictionary, strategy matching is impossible.

Source

Thrown at BetterGenshinImpact/GameTask/AutoLeyLineOutcrop/AutoLeyLineOutcropTask.cs:378

            {
                // Manual flow: detect the ley line on the big map.
                await FindLeyLineOutcrop(_taskParam.Country, _taskParam.LeyLineOutcropType);
            }

            var foundStrategy = await ExecuteMatchingStrategy();
            if (!foundStrategy)
            {
                HandleNoStrategyFound();
                return;
            }
        }
    }

    private async Task<bool> ExecuteMatchingStrategy()
    {
        if (_configData?.LeyLinePositions == null)
        {
            throw new Exception("地脉花策略配置缺失");
        }

        if (!_configData.LeyLinePositions.TryGetValue(_taskParam.Country, out var positions))
        {
            return false;
        }

        foreach (var position in positions)
        {
            if (IsNearPosition(_leyLineX, _leyLineY, position.X, position.Y, _configData.ErrorThreshold))
            {
                _logger.LogInformation("匹配策略: {Strategy} order={Order}", position.Strategy, position.Order);
                await ExecutePathsUsingNodeData(position);
                return true;
            }
        }

        return false;

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Verify config.json contains a non-null LeyLinePositions object with entries for each supported country.
  2. Restore config.json from the bundled/default version.
  3. If the schema changed, replace the config with the version matching the current code.
  4. Add a post-load validation in LoadConfigData to fail early with a clearer message if LeyLinePositions is null.
Defensive patterns

Strategy: validation

Validate before calling

// After LoadConfigData, verify LeyLinePositions is populated
if (_configData?.LeyLinePositions == null)
{
    Logger.LogError("地脉花策略配置缺失,请检查 config.json");
    throw new NormalEndException("配置文件缺少 LeyLinePositions 数据");
}

Type guard

public static bool HasLeyLinePositions(AutoLeyLineConfigData? config)
{
    return config?.LeyLinePositions != null && config.LeyLinePositions.Count > 0;
}

Prevention

When it happens

Trigger: Called from RunLeyLineChallenges after a ley line is located on the map. Fires when LoadConfigData did not run or produced a config without LeyLinePositions. This can happen if config.json was loaded but the LeyLinePositions property was missing/null in the JSON (System.Text.Json leaves it null rather than failing), or if _configData was somehow cleared between load and use.

Common situations: config.json exists and parses but is missing the LeyLinePositions section (schema mismatch after an update); LoadConfigData threw and was caught somewhere, leaving _configData null; the config was hand-edited and the LeyLinePositions object was accidentally deleted.

Related errors


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