babalae/better-genshin-impact · error · ArgumentException
{paramName} 不能为空
Error message
{paramName} 不能为空 What it means
The final guard in ParseCollection<T> rejects an empty collection with ArgumentException. A zero-length match set is useless for OCR/text matching (no candidate can ever succeed) and would mask caller bugs, so the helper treats it as a contract violation rather than returning an unusable locator.
Source
Thrown at BetterGenshinImpact/Core/BgiVision/BvPage.cs:176
if (values is string || values is not IEnumerable enumerable)
{
throw new ArgumentException($"{paramName} 必须是集合或 JS Array", paramName);
}
List<T> result = [];
foreach (var value in enumerable)
{
if (value is not T typedValue)
{
throw new ArgumentException($"{paramName} 中的每个元素都必须是 {typeof(T).Name}", paramName);
}
result.Add(typedValue);
}
if (result.Count == 0)
{
throw new ArgumentException($"{paramName} 不能为空", paramName);
}
return result;
}
}
View on GitHub (pinned to a7cb36712d)
Solutions
- Ensure at least one non-empty candidate is present before calling.
- If the list is dynamic, check .Any() first and skip/handle the empty case explicitly.
- Default to a sensible fallback candidate rather than an empty array.
Example fix
// before
var loc = page.GetByAnyText(candidates); // candidates may be empty
// after
if (candidates.Length == 0)
{
// handle missing-text case (skip, log, default)
}
else
{
var loc = page.GetByAnyText(candidates);
} Defensive patterns
Strategy: validation
Validate before calling
if (candidates is null || !candidates.Any())
{
// handle empty case (skip, default, log)
return;
}
var loc = page.GetByAnyText(candidates); Type guard
static bool IsNonEmpty<T>(IEnumerable<T>? xs) => xs?.Any() == true;
Prevention
- Check .Any() on dynamically built candidate lists before calling.
- Default to a known-good fallback candidate instead of an empty array.
- Treat an empty match set as a configuration error and surface it.
When it happens
Trigger: GetByAnyText(new string[]{}); GetByAnyText([]) from JS; a dynamically-built list that ended up empty after filtering.
Common situations: Localization tables with no entries for a given key; filters that remove all candidates; config-driven arrays left uninitialized.
Related errors
- retryInterval 必须大于 0
- 候选文本不能包含空字符串或纯空白字符串
- {paramName} 必须是集合或 JS Array
- {paramName} 中的每个元素都必须是 {typeof(T).Name}
- 角色名集合不能为空。
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/64b3f36866529a1f.
Report an issue: GitHub.