babalae/better-genshin-impact · error · ArgumentException

至少需要指定一个读取分类。

Error message

至少需要指定一个读取分类。

What it means

Constructor argument check: `categories` must not be `CharacterDevelopmentCategory.None`. The flags enum uses `None = 0` to mean "nothing requested", and the task has nothing to do without at least one of Attribute/Weapon/Talent, so it rejects `None` with `ArgumentException`.

Source

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

    private AvatarGridIconRecognizer Recognizer =>
        _recognizer ?? throw new InvalidOperationException("角色养成识别:头像识别器尚未初始化。");

    private CharacterSelectionTarget CurrentTarget =>
        _currentTarget ?? throw new InvalidOperationException("角色养成识别:当前角色尚未初始化。");

    private CharacterDevelopmentResult CurrentResult =>
        _currentResult ?? throw new InvalidOperationException("角色养成识别:当前结果尚未初始化。");

    public CharacterDevelopmentStateMachineTask(IReadOnlyList<string> characterNames, CharacterDevelopmentCategory categories)
    {
        if (characterNames.Count == 0)
        {
            throw new ArgumentException("至少需要指定一个角色。", nameof(characterNames));
        }

        if (categories == CharacterDevelopmentCategory.None)
        {
            throw new ArgumentException("至少需要指定一个读取分类。", nameof(categories));
        }

        _categories = categories;
        _targets = characterNames.Select(CharacterSelectionHelper.CreateTarget).ToList();
        var captureRect = TaskContext.Instance().SystemInfo.ScaleMax1080PCaptureRect;
        _assets = CharacterDevelopmentAssets.Get(captureRect.Width, captureRect.Height);

        RegisterStateMethodsByAttribute();
        RegisterStateTransitions(
            (CharacterDevelopmentState.Unknown, [CharacterDevelopmentState.MainUi, CharacterDevelopmentState.OpenCharacterList]),
            (CharacterDevelopmentState.MainUi, [CharacterDevelopmentState.OpenCharacterList]),
            (CharacterDevelopmentState.OpenCharacterList, [CharacterDevelopmentState.OpenFilterPanel]),
            (CharacterDevelopmentState.OpenFilterPanel, [CharacterDevelopmentState.FilterPanel]),
            (CharacterDevelopmentState.FilterPanel, [CharacterDevelopmentState.SelectElementFilter, CharacterDevelopmentState.SelectWeaponFilter]),
            (CharacterDevelopmentState.SelectElementFilter, [CharacterDevelopmentState.SelectWeaponFilter]),
            (CharacterDevelopmentState.SelectWeaponFilter, [CharacterDevelopmentState.ConfirmFilterPanel]),
            (CharacterDevelopmentState.ConfirmFilterPanel, [CharacterDevelopmentState.FindAndClickAvatar]),
            (CharacterDevelopmentState.FindAndClickAvatar, [CharacterDevelopmentState.SelectedCharacter]),

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Pass at least one flag, e.g. `CharacterDevelopmentCategory.Attribute | CharacterDevelopmentCategory.Weapon`.
  2. When parsing user input, map empty/null to `All` (as `GetCharacter` does) instead of `None`.
  3. Validate the parsed flags are non-zero before constructing the task.

Example fix

// before
var cats = ParseCategories(userInput); // may be None
var task = new CharacterDevelopmentStateMachineTask(names, cats);

// after
var cats = ParseCategories(userInput);
if (cats == CharacterDevelopmentCategory.None) cats = CharacterDevelopmentCategory.All;
var task = new CharacterDevelopmentStateMachineTask(names, cats);
Defensive patterns

Strategy: validation

Validate before calling

if (categories == CharacterDevelopmentCategory.None)
    categories = CharacterDevelopmentCategory.All; // or throw at the call site

Prevention

When it happens

Trigger: Passing `CharacterDevelopmentCategory.None` (value 0), or a default/uninitialized `CharacterDevelopmentCategory` variable, or a category string that `ParseCategories` maps to `None`.

Common situations: Caller forgets to set a category; config field left empty and parsed as None; passing `default(CharacterDevelopmentCategory)`.

Related errors


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