babalae/better-genshin-impact · error · ArgumentException

角色名不能为空。

Error message

角色名不能为空。

What it means

`CharacterSelectionHelper.CreateTarget` rejects a null/empty/whitespace character name with `ArgumentException`. A target with no name cannot be matched against the avatar grid or configured aliases, so it fails fast at target construction (called from the state-machine constructor for every name in the list).

Source

Thrown at BetterGenshinImpact/GameTask/CharacterDevelopment/CharacterSelectionHelper.cs:64

/// </summary>
internal sealed record CharacterCardRect(Rect CardRect, Rect AvatarRect, Rect ElementRect);

/// <summary>
/// 角色列表筛选、卡片定位和头像匹配的专用实现,不与旧角色切换网格共享。
/// </summary>
internal static class CharacterSelectionHelper
{
    /// <summary>头像 embedding 余弦相似度的最低接受分数。</summary>
    internal const double MatchThreshold = 0.7;
    private const int EmptyDetectionRetryCount = 3;
    private static readonly Rect GridRoi1080 = new(40, 76, 641, 897);

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

        var standardName = ToConfiguredAvatarName(normalizedName);
        if (standardName == "旅行者")
        {
            return new CharacterSelectionTarget(
                "旅行者",
                ["空", "荧"],
                true,
                "单手剑",
                true,
                true);
        }

        if (standardName is "空" or "荧")
        {
            return new CharacterSelectionTarget(
                standardName,

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Trim and validate each character name before adding it to the list passed to the task.
  2. Filter out empty entries when splitting user-provided name lists.
  3. In `GetCharacter`, ensure `NormalizeCharacterName` never yields an empty string (or throw a clearer error there).

Example fix

// before
var names = userInput.Split(';'); // may contain ""
var targets = names.Select(CharacterSelectionHelper.CreateTarget); // throws

// after
var names = userInput.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
var targets = names.Select(CharacterSelectionHelper.CreateTarget);
Defensive patterns

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: Passing `null`, `""`, `" "`, or a name that trims to empty to `CreateTarget`; a character list containing a blank entry; `GetCharacter(null)` where normalization yields empty.

Common situations: User input not trimmed/validated before building the character list; a config file with an empty name field; a stray empty string in a comma-split list.

Related errors


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