babalae/better-genshin-impact · warning · ArgumentException
WebView 操作名称不能为空。
Error message
WebView 操作名称不能为空。
What it means
Thrown by SendWebViewMessageAsync when the operation parameter is null, empty, or whitespace. This is an ArgumentException (not InvalidDataException) because it is a caller-side contract violation, not a wire-protocol error. The operation name identifies the WebView message type (e.g., a JavaScript function name or event identifier) and must be non-empty.
Source
Thrown at BetterGenshinImpact/Service/Instance/InstanceService.cs:201
InstanceOperations.WebViewList,
null,
RequestTimeout,
cancellationToken).ConfigureAwait(false);
EnsureSuccessfulResponse(response);
return response.Data?.ToObject<WebViewListResponse>(InstanceIpcProtocol.Serializer)
?.Endpoints
?? [];
}
public async Task SendWebViewMessageAsync(
int targetProcessId,
string operation,
JToken? data = null,
CancellationToken cancellationToken = default)
{
if (string.IsNullOrWhiteSpace(operation))
{
throw new ArgumentException("WebView 操作名称不能为空。", nameof(operation));
}
if (Context.InstanceType == BetterGiInstanceType.WebView)
{
throw new InvalidOperationException("WebView 不能向其他 WebView 发送消息。");
}
if (Context.InstanceType == BetterGiInstanceType.Primary)
{
if (!_messageState.WebViewConnectionsByProcessId.TryGetValue(
targetProcessId,
out var target))
{
throw new InvalidOperationException(
$"WebView 进程 {targetProcessId} 当前不在线。");
}
var targetResponse = await target.Connection.SendRequestAsync(
InstanceOperations.WebViewMessage,View on GitHub (pinned to a7cb36712d)
Solutions
- Ensure the operation name is always a non-empty string constant or a validated config value before calling SendWebViewMessageAsync.
- Guard the call site: check string.IsNullOrWhiteSpace(operation) and provide a meaningful default or skip the call.
- If the operation comes from config, validate it at application startup and fail fast with a clear message rather than at the IPC call site.
Example fix
// before
await instanceService.SendWebViewMessageAsync(pid, operationNameFromConfig, data);
// after
if (string.IsNullOrWhiteSpace(operationNameFromConfig))
{
throw new InvalidOperationException("WebView 操作名称未配置。");
}
await instanceService.SendWebViewMessageAsync(pid, operationNameFromConfig, data); Defensive patterns
Strategy: validation
Validate before calling
// Validate before calling
if (string.IsNullOrWhiteSpace(operation))
{
throw new ArgumentException("必须提供 WebView 操作名称。", nameof(operation));
}
await instanceService.SendWebViewMessageAsync(pid, operation, data); Prevention
- Always pass a non-empty operation string constant or validated config value.
- Use nameof() in ArgumentException so the caller knows which parameter is wrong.
- Validate config-sourced operation names at startup, not at call time.
When it happens
Trigger: Any caller invokes SendWebViewMessageAsync(targetProcessId, operation, data) with operation being null, string.Empty, or a whitespace-only string. This typically comes from application code that builds the operation name dynamically (e.g., from user input, config, or a variable that was never assigned).
Common situations: A configuration value for the WebView operation name is missing or blank; a variable intended to hold the operation name was not initialized before the call; a refactoring changed the operation source and left it null; unit test code that passes a default/empty string.
Related errors
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/6d3fb7cf4edfc575.
Report an issue: GitHub.