babalae/better-genshin-impact · error · ArgumentException

读取分类不能为空字符串。

Error message

读取分类不能为空字符串。

What it means

Thrown by ParseCategories when the categories argument is a non-null string that is empty or whitespace-only. Null is treated as 'all categories', but an explicitly empty string is ambiguous and rejected. Pass null for 'all' or provide valid category names.

Source

Thrown at BetterGenshinImpact/GameTask/CharacterDevelopment/CharacterDevelopmentTask.cs:169

        var name = characterName?.Trim() ?? string.Empty;
        if (string.IsNullOrWhiteSpace(name))
        {
            throw new ArgumentException("角色名不能为空。", nameof(characterName));
        }

        return name;
    }

    internal static CharacterDevelopmentCategory ParseCategories(string? categories)
    {
        if (categories == null)
        {
            return CharacterDevelopmentCategory.All;
        }

        if (string.IsNullOrWhiteSpace(categories))
        {
            throw new ArgumentException("读取分类不能为空字符串。", nameof(categories));
        }

        CharacterDevelopmentCategory result = CharacterDevelopmentCategory.None;
        foreach (var rawCategory in categories.Split(';', StringSplitOptions.None))
        {
            var category = rawCategory.Trim();
            result |= category switch
            {
                "属性" => CharacterDevelopmentCategory.Attribute,
                "武器" => CharacterDevelopmentCategory.Weapon,
                "天赋" => CharacterDevelopmentCategory.Talent,
                _ => throw new ArgumentException($"未知的角色信息分类:{rawCategory}", nameof(categories))
            };
        }

        return result;
    }
}

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Pass null instead of an empty string to select all categories.
  2. Pass a valid category string like '属性;武器;天赋' for specific categories.
  3. Fix upstream code that produces empty strings where null is expected.

Example fix

// before (wrong)
await dev.GetMultiCharacters(['钟离'], '');
// after (all categories)
await dev.GetMultiCharacters(['钟离'], null);
// after (specific categories)
await dev.GetMultiCharacters(['钟离'], '属性;天赋');
Defensive patterns

Strategy: validation

Validate before calling

// Pass null for all categories, or a valid string
string? safeCategories = string.IsNullOrWhiteSpace(categories) ? null : categories;
await dev.GetMultiCharacters(names, safeCategories);

Try / catch

try
{
    await dev.GetMultiCharacters(names, categories);
}
catch (ArgumentException ex) when (ex.Message.Contains("读取分类不能为空"))
{
    // Pass null instead of empty string
}

Prevention

When it happens

Trigger: Called from GetMultiCategories or GetMultiCharacters → ParseCategories(categories). categories is a non-null string where string.IsNullOrWhiteSpace returns true.

Common situations: Caller passes '' or ' ' explicitly instead of null; a variable intended to be null is initialized to empty string; configuration value defaults to empty string.

Related errors


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