babalae/better-genshin-impact · error · ArgumentOutOfRangeException

未知角色信息分类。

Error message

未知角色信息分类。

What it means

`GetCategoryText` maps each `CharacterDevelopmentCategory` flag to its Chinese tab label and throws `ArgumentOutOfRangeException` for any unmapped value. With Attribute/Weapon/Talent all handled, the default is unreachable unless a new enum member is added without updating the switch or an invalid flag combination (a numeric cast) is passed.

Source

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

    {
        var captureRect = TaskContext.Instance().SystemInfo.ScaleMax1080PCaptureRect;
        return new Rect(0, 0, (int)(captureRect.Width * 0.2), captureRect.Height);
    }

    private static Rect GetTalentListRoi(ImageRegion capture)
    {
        var x = (int)(capture.Width * 0.8);
        return new Rect(x, 0, capture.Width - x, capture.Height);
    }

    private static string GetCategoryText(CharacterDevelopmentCategory category)
    {
        return category switch
        {
            CharacterDevelopmentCategory.Attribute => "属性",
            CharacterDevelopmentCategory.Weapon => "武器",
            CharacterDevelopmentCategory.Talent => "天赋",
            _ => throw new ArgumentOutOfRangeException(nameof(category), category, "未知角色信息分类。")
        };
    }
}

View on GitHub (pinned to a7cb36712d)

Solutions

  1. When adding a category, update `GetCategoryText`, `GetOrderedCategories`, and the `ReadCategory` switch together.
  2. Ensure only valid, set flags reach `GetCategoryText` (filter `None` upstream).
  3. In tests, pass real enum members, not arbitrary casts.

Example fix

// before
GetCategoryText((CharacterDevelopmentCategory)99); // throws

// after: pass a real flag
GetCategoryText(CharacterDevelopmentCategory.Attribute);
Defensive patterns

Strategy: type-guard

Type guard

static bool IsKnownCategory(CharacterDevelopmentCategory c) =>
    c == CharacterDevelopmentCategory.Attribute
    || c == CharacterDevelopmentCategory.Weapon
    || c == CharacterDevelopmentCategory.Talent;

Prevention

When it happens

Trigger: A future `CharacterDevelopmentCategory` member not handled in the switch; an explicitly cast invalid integer passed as the category; `None` reaching this function (it is normally filtered earlier).

Common situations: Enum extension without updating all exhaustiveness switches; tests passing `default`/`(CharacterDevelopmentCategory)999`.

Related errors


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