babalae/better-genshin-impact · error · InvalidDataException

物品原型表存在列数不足的记录。

Error message

物品原型表存在列数不足的记录。

What it means

Thrown by ExtractWeaponNames while iterating CSV rows when a row's column count is less than requiredColumnCount (derived from the maximum index of item_class_id and item_name columns + 1). This protects the subsequent indexed access columns[itemClassIdIndex] / columns[itemNameIndex] from IndexOutOfRange. It indicates the item.csv file is internally inconsistent — the header declared the columns but at least one data row is shorter.

Source

Thrown at BetterGenshinImpact/GameTask/CharacterDevelopment/WeaponNameMatcher.cs:98

    }

    /// <summary>
    /// 从物品原型表中提取并去重标准武器名称。
    /// </summary>
    internal static IReadOnlyList<string> ExtractWeaponNames(
        IReadOnlyList<string> headers,
        IEnumerable<string[]> rows)
    {
        var itemClassIdIndex = FindRequiredColumn(headers, "item_class_id");
        var itemNameIndex = FindRequiredColumn(headers, "item_name");
        var requiredColumnCount = Math.Max(itemClassIdIndex, itemNameIndex) + 1;
        var names = new HashSet<string>(StringComparer.Ordinal);

        foreach (var columns in rows)
        {
            if (columns.Length < requiredColumnCount)
            {
                throw new InvalidDataException("物品原型表存在列数不足的记录。");
            }

            if (!columns[itemClassIdIndex].Trim().StartsWith("weapon:", StringComparison.OrdinalIgnoreCase))
            {
                continue;
            }

            var name = columns[itemNameIndex].Trim();
            if (!string.IsNullOrWhiteSpace(name))
            {
                names.Add(name);
            }
        }

        if (names.Count == 0)
        {
            throw new InvalidDataException("物品原型表中没有 item_class_id 以 weapon: 开头的武器记录。");
        }

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Restore item.csv from a clean build or the upstream repository.
  2. Open item.csv in a text editor and check for truncated rows, missing commas, or unescaped quotes near the error.
  3. Validate every row has at least as many columns as the header before loading.

Example fix

null
Defensive patterns

Strategy: validation

Validate before calling

foreach (var row in rows)
{
    if (row.Length < requiredColumnCount) continue; // skip malformed rows
    // process row
}

Type guard

null

Try / catch

try { ExtractWeaponNames(headers, rows); }
catch (InvalidDataException ex) { /* log corrupt CSV row, restore asset */ }

Prevention

When it happens

Trigger: item.csv contains a malformed row with fewer fields than the header, e.g., a trailing line, a partially written row, or a quoting error that caused TextFieldParser to split incorrectly.

Common situations: The bundled item.csv was hand-edited or partially overwritten. A game version update changed the CSV export format but only some rows were regenerated. An encoding or line-ending issue (mixed CRLF/LF) corrupted field splitting.

Related errors


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