babalae/better-genshin-impact · error · Exception

未找到国家 {country} 的位置信息

Error message

未找到国家 {country} 的位置信息

What it means

Thrown by FindLeyLineOutcrop when the requested country key is absent from _configData.MapPositions, or its position list is empty. The routing logic needs at least one coordinate to move the map to.

Source

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

        }

        return new NodeData
        {
            Nodes = nodes,
            Indexes = raw.Indexes
        };
    }

    private async Task FindLeyLineOutcrop(string country, string type)
    {
        if (_configData?.MapPositions == null)
        {
            throw new Exception("地图位置配置缺失");
        }

        if (!_configData.MapPositions.TryGetValue(country, out var positions) || positions.Count == 0)
        {
            throw new Exception($"未找到国家 {country} 的位置信息");
        }

        await _returnMainUiTask.Start(_ct);
        await _tpTask.OpenBigMapUi();

        await _tpTask.MoveMapTo(positions[0].X, positions[0].Y, MapTypes.Teyvat.ToString());
        var found = await LocateLeyLineOutcrop(type);
        if (found)
        {
            return;
        }

        for (var i = 1; i < positions.Count; i++)
        {
            var pos = positions[i];
            _logger.LogInformation("尝试定位地脉花: {Name}", pos.Name ?? $"{pos.X},{pos.Y}");
            await _tpTask.MoveMapTo(pos.X, pos.Y, MapTypes.Teyvat.ToString());
            if (await LocateLeyLineOutcrop(type))

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Verify the country string passed to FindLeyLineOutcrop exactly matches a key in MapPositions (mind full-width characters and exact glyphs like 蒙德/璃月/稻妻/须弥/枫丹).
  2. Add the missing country entry with at least one position to the config/data file.
  3. Guard the caller to only request countries known to exist in MapPositions.Keys.

Example fix

// before
if (!_configData.MapPositions.TryGetValue(country, out var positions) || positions.Count == 0)
{
    throw new Exception($"未找到国家 {country} 的位置信息");
}

// after
if (!_configData.MapPositions.TryGetValue(country, out var positions))
{
    throw new ArgumentException($"未找到国家 {country} 的位置信息。可用国家: {string.Join(", ", _configData.MapPositions.Keys)}", nameof(country));
}
if (positions.Count == 0)
{
    throw new InvalidOperationException($"国家 {country} 的位置列表为空");
}
Defensive patterns

Strategy: validation

Validate before calling

if (!_configData.MapPositions.ContainsKey(country) || _configData.MapPositions[country].Count == 0)
{
    throw new ArgumentException($"国家 {country} 无位置信息。可用: {string.Join(", ", _configData.MapPositions.Keys)}", nameof(country));
}

Type guard

bool CountryAvailable(LeyLineConfig c, string country) => c.MapPositions.TryGetValue(country, out var p) && p.Count > 0;

Prevention

When it happens

Trigger: FindLeyLineOutcrop(country, type) is called with a country string that does not match any key in MapPositions, or matches a key whose List is empty (TryGetValue succeeds but positions.Count == 0).

Common situations: Country name typo or casing mismatch between caller and config; the region is not yet supported in the data file; the user disabled a country leaving an empty list.

Related errors


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