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
- Remove empty or whitespace-only entries from the array before calling.
- Validate each name with a truthiness/trim check before passing.
- 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
- Trim and validate each character name is non-empty before passing.
- Remove empty or whitespace-only strings from the array.
- Use LINQ Where(n => !string.IsNullOrWhiteSpace(n)) to filter.
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
- 读取分类不能为空字符串。
- 多角色接口需要字符串集合或 JS Array,单个字符串请使用 GetCharacter。
- 角色名参数必须是字符串集合或 JS Array。
- 角色名集合中的每个元素都必须是字符串。
- 角色名集合不能为空。
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/b7d24f3550b1a980.
Report an issue: GitHub.