babalae/better-genshin-impact · error · ArgumentException
至少需要指定一个角色。
Error message
至少需要指定一个角色。
What it means
Constructor argument check: `CharacterDevelopmentStateMachineTask` refuses an empty `characterNames` collection. The task must read at least one character, so an empty list is a programmer error and fails fast with `ArgumentException`.
Source
Thrown at BetterGenshinImpact/GameTask/CharacterDevelopment/CharacterDevelopmentTask.cs:267
private int _talentIndex;
private readonly HashSet<string> _readTalentTypes = new(StringComparer.Ordinal);
protected override ILogger Logger => _logger;
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]),View on GitHub (pinned to a7cb36712d)
Solutions
- Validate that the character list is non-empty before constructing the task.
- Ensure the caller (e.g. `GetCharacter`/`GetCharacters`) forwards at least one non-empty name.
- Guard the UI/script layer so the task cannot be started with zero characters.
Example fix
// before
var task = new CharacterDevelopmentStateMachineTask([], cats);
// after
if (characterNames is null || characterNames.Count == 0)
throw new ArgumentException("至少需要指定一个角色。", nameof(characterNames));
var task = new CharacterDevelopmentStateMachineTask(characterNames, cats); Defensive patterns
Strategy: validation
Validate before calling
if (characterNames is null || characterNames.Count == 0)
throw new ArgumentException("至少需要指定一个角色。", nameof(characterNames)); Prevention
- Validate the character list at the UI/script boundary before constructing the task.
- Filter empty entries from user-provided name lists.
- Ensure batch callers always forward at least one name.
When it happens
Trigger: Constructing the task with `new List<string>()`, an empty array `[]`, or a collection whose only element normalizes to nothing upstream; calling a hypothetical batch API that forwards an empty list.
Common situations: A script/config that supplies no character names; a UI that lets the user start the task without selecting any character; passing through an unvalidated list from user input.
Related errors
- 至少需要指定一个读取分类。
- 多角色接口需要字符串集合或 JS Array,单个字符串请使用 GetCharacter。
- 角色名参数必须是字符串集合或 JS Array。
- 角色名集合中的每个元素都必须是字符串。
- 角色名集合不能为空。
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/97e5572c9ecc3fd1.
Report an issue: GitHub.