babalae/better-genshin-impact · error · ArgumentException

角色名不能为空。

Error message

角色名不能为空。

What it means

Thrown by NormalizeCharacterName (called from ParseCharacterNames for each name) when a character name is null, empty, or whitespace-only after trimming. Each individual name must be non-empty and meaningful.

Source

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

            }

            names.Add(NormalizeCharacterName(name));
        }

        if (names.Count == 0)
        {
            throw new ArgumentException("角色名集合不能为空。", nameof(characterNames));
        }

        return names;
    }

    private static string NormalizeCharacterName(string characterName)
    {
        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;

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Remove empty or whitespace-only entries from the array before calling.
  2. Validate each name with a truthiness/trim check before passing.
  3. Ensure character names are correctly typed without extra spaces.

Example fix

// before (wrong)
await dev.GetMultiCharacters(['', '钟离']);
// after
await dev.GetMultiCharacters(['钟离']);
Defensive patterns

Strategy: validation

Validate before calling

// Remove empty or whitespace-only names before calling
var validNames = names.Where(n => !string.IsNullOrWhiteSpace(n?.ToString())).Cast<string>().ToList();

Type guard

static bool AllNamesNonEmpty(IEnumerable<string> names)
{
    return names.All(n => !string.IsNullOrWhiteSpace(n));
}

Try / catch

try
{
    await dev.GetMultiCharacters(names);
}
catch (ArgumentException ex) when (ex.Message.Contains("角色名不能为空"))
{
    // Remove blank entries from the collection
}

Prevention

When it happens

Trigger: Called from ParseCharacterNames → NormalizeCharacterName(name). The name string is null, empty, or contains only whitespace after Trim().

Common situations: Array contains empty strings: ['', '钟离']; names with only spaces: [' ']; null elements that passed the earlier 'is not string' check are impossible, but trimmed-empty strings reach here.

Related errors


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