{"record":{"id":"6d3fb7cf4edfc575","repo":"babalae/better-genshin-impact","slug":"webview","errorCode":null,"errorMessage":"WebView 操作名称不能为空。","messagePattern":"WebView 操作名称不能为空。","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"warning","filePath":"BetterGenshinImpact/Service/Instance/InstanceService.cs","lineNumber":201,"sourceCode":"            InstanceOperations.WebViewList,\n            null,\n            RequestTimeout,\n            cancellationToken).ConfigureAwait(false);\n        EnsureSuccessfulResponse(response);\n        return response.Data?.ToObject<WebViewListResponse>(InstanceIpcProtocol.Serializer)\n                   ?.Endpoints\n               ?? [];\n    }\n\n    public async Task SendWebViewMessageAsync(\n        int targetProcessId,\n        string operation,\n        JToken? data = null,\n        CancellationToken cancellationToken = default)\n    {\n        if (string.IsNullOrWhiteSpace(operation))\n        {\n            throw new ArgumentException(\"WebView 操作名称不能为空。\", nameof(operation));\n        }\n        if (Context.InstanceType == BetterGiInstanceType.WebView)\n        {\n            throw new InvalidOperationException(\"WebView 不能向其他 WebView 发送消息。\");\n        }\n\n        if (Context.InstanceType == BetterGiInstanceType.Primary)\n        {\n            if (!_messageState.WebViewConnectionsByProcessId.TryGetValue(\n                    targetProcessId,\n                    out var target))\n            {\n                throw new InvalidOperationException(\n                    $\"WebView 进程 {targetProcessId} 当前不在线。\");\n            }\n\n            var targetResponse = await target.Connection.SendRequestAsync(\n                InstanceOperations.WebViewMessage,","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/Instance/InstanceService.cs#L183-L219","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nawait instanceService.SendWebViewMessageAsync(pid, operationNameFromConfig, data);\n\n// after\nif (string.IsNullOrWhiteSpace(operationNameFromConfig))\n{\n    throw new InvalidOperationException(\"WebView 操作名称未配置。\");\n}\nawait instanceService.SendWebViewMessageAsync(pid, operationNameFromConfig, data);","handlingStrategy":"validation","validationCode":"// Validate before calling\nif (string.IsNullOrWhiteSpace(operation))\n{\n    throw new ArgumentException(\"必须提供 WebView 操作名称。\", nameof(operation));\n}\nawait instanceService.SendWebViewMessageAsync(pid, operation, data);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["api-contract","validation","webview","argument-error"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}