{"record":{"id":"830f90bb4539f3ef","repo":"babalae/better-genshin-impact","slug":"requestid-cannot-be-empty","errorCode":null,"errorMessage":"requestId cannot be empty","messagePattern":"requestId cannot be empty","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"warning","filePath":"BetterGenshinImpact/Core/Script/Dependence/HtmlMask.cs","lineNumber":207,"sourceCode":"        queue.Enqueue(new Message\n        {\n            Url = url,\n            Data = ParseData(jsonData)\n        });\n\n        HtmlMaskWindow.NotifyFlush(windowId);\n    }\n\n    /// <summary>\n    /// 响应 HTML 页面通过 window.htmlMask.request(...) 发起的请求。\n    /// </summary>\n    /// <param name=\"windowId\">HTML 遮罩窗口 ID。</param>\n    /// <param name=\"requestId\">从 Receive/Poll/PollAll 返回消息的 requestId 字段取得，不能由脚本自行生成。</param>\n    /// <param name=\"jsonData\">响应数据，必须是合法 JSON 字符串。</param>\n    public void Respond(string windowId, string requestId, string jsonData)\n    {\n        if (string.IsNullOrWhiteSpace(requestId))\n            throw new ArgumentException(\"requestId cannot be empty\", nameof(requestId));\n\n        if (!HtmlMaskWindow.Exists(windowId) || !_toHtmlQueues.TryGetValue(windowId, out var queue))\n            throw new InvalidOperationException($\"HTML遮罩窗口不存在或已关闭: {windowId}\");\n\n        queue.Enqueue(new Message\n        {\n            Url = \"/__response__\",\n            Data = ParseData(jsonData),\n            RequestId = requestId\n        });\n\n        HtmlMaskWindow.NotifyFlush(windowId);\n    }\n    \n    /// <summary>\n    /// 发送请求到HTML并等待响应\n    /// </summary>\n    /// <param name=\"windowId\">目标窗口ID</param>","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Script/Dependence/HtmlMask.cs#L189-L225","documentation":"Thrown by HtmlMask.Respond when requestId is null, empty, or whitespace. The requestId is the correlation ID that ties a response back to a pending request from the HTML page (obtained from Receive/Poll/PollAll message objects). It must never be generated by the script itself.","triggerScenarios":"Calling htmlMask.Respond(windowId, requestId, jsonData) where requestId is empty — typically because the script forgot to extract it from the received message, or passed a default/empty string.","commonSituations":"Script hardcodes requestId as \"\" instead of reading it from the message returned by Receive/Poll. The message object's requestId field was not populated (e.g., for a non-request message). Refactor changed the message field access path and left requestId null.","solutions":["Always extract requestId from the message object returned by Receive, Poll, or PollAll.","Check string.IsNullOrWhiteSpace(requestId) before calling Respond and skip or log a warning.","Only call Respond for messages that have a non-empty requestId (request-type messages, not push-type)."],"exampleFix":"// before\nhtmlMask.Respond(windowId, \"\", responseData);\n\n// after\nvar msg = htmlMask.Receive(windowId, timeoutMs);\nif (msg != null && !string.IsNullOrWhiteSpace(msg.requestId))\n{\n    htmlMask.Respond(windowId, msg.requestId, responseData);\n}\nelse\n{\n    _logger.LogDebug(\"No pending request to respond to\");\n}","handlingStrategy":"validation","validationCode":"// Validate requestId before calling Respond\nif (string.IsNullOrWhiteSpace(requestId))\n{\n    _logger.LogDebug(\"Cannot respond: requestId is empty\");\n    return;\n}\nhtmlMask.Respond(windowId, requestId, jsonData);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always extract requestId from the message returned by Receive/Poll/PollAll.","Never generate requestId yourself — it must come from the HTML page's request.","Only call Respond for request-type messages that have a non-empty requestId."],"tags":["html-mask","validation","message-passing","request-response","argument"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}