{"record":{"id":"fb04f4add23efc50","repo":"chenhg5/cc-connect","slug":"googlechat-build-update-request-w","errorCode":null,"errorMessage":"googlechat: build update request: %w","messagePattern":"googlechat: build update request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/googlechat/streaming.go","lineNumber":89,"sourceCode":"\t}\n\treturn u, b, nil\n}\n\n// UpdateMessage patches the preview message text in place. The engine passes the\n// handle returned by SendPreviewStart (not the reply context). Implements\n// core.MessageUpdater.\nfunc (p *Platform) UpdateMessage(ctx context.Context, handle any, content string) error {\n\th, ok := handle.(*previewHandle)\n\tif !ok {\n\t\treturn fmt.Errorf(\"googlechat: invalid preview handle type %T\", handle)\n\t}\n\turl, body, err := buildUpdateRequest(h.name, content)\n\tif err != nil {\n\t\treturn err\n\t}\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPatch, url, bytes.NewReader(body))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"googlechat: build update request: %w\", err)\n\t}\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\tresp, err := p.doRequest(req)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif _, err := io.Copy(io.Discard, resp.Body); err != nil {\n\t\t_ = resp.Body.Close()\n\t\treturn fmt.Errorf(\"googlechat: drain update response body: %w\", err)\n\t}\n\tif err := resp.Body.Close(); err != nil {\n\t\treturn fmt.Errorf(\"googlechat: close update response body: %w\", err)\n\t}\n\treturn nil\n}\n\nvar (\n\t_ core.MessageUpdater = (*Platform)(nil)","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/googlechat/streaming.go#L71-L107","documentation":"This error wraps a failure from http.NewRequestWithContext while building the PATCH request that updates a streaming-preview message via spaces.messages.patch. It is thrown in UpdateMessage after the handle type check succeeds and buildUpdateRequest returned a valid URL and body. Since the URL comes from chatAPIBase + a validated message name and the body is a valid byte reader, this branch is defensive and rarely fires in production.","triggerScenarios":"http.NewRequestWithContext(ctx, http.MethodPatch, url, bytes.NewReader(body)) returns an error inside UpdateMessage — practically only when the URL fails to parse (e.g. chatAPIBase misconfigured with invalid characters/spaces) or the context is already invalid in a way the constructor rejects.","commonSituations":"A misconfigured API base URL containing characters that make the URL unparseable; a malformed msgName in the previewHandle (e.g. containing spaces or control characters) corrupting the final URL.","solutions":["Verify chatAPIBase is a clean, valid URL prefix (https://chat.googleapis.com/v1/)","Check the message name in the previewHandle for invalid URL characters","Confirm the context passed to UpdateMessage is a healthy, non-cancelled context","Log the constructed URL (with the message name) to spot malformed segments"],"exampleFix":"// before\nu := chatAPIBase + msgName + \"?updateMask=text\"\n// after: validate segments before building the URL\nif strings.ContainsAny(msgName, \" \\t\\r\\n\") {\n    return \"\", nil, fmt.Errorf(\"googlechat: invalid message name %q\", msgName)\n}\nu := chatAPIBase + msgName + \"?updateMask=text\"","handlingStrategy":"try-catch","validationCode":"// validate config before starting the platform\nif _, err := url.Parse(chatAPIBase); err != nil {\n    return fmt.Errorf(\"invalid googlechat chatAPIBase %q: %w\", chatAPIBase, err)\n}","typeGuard":null,"tryCatchPattern":"if err := p.UpdateMessage(ctx, handle, text); err != nil {\n    if strings.Contains(err.Error(), \"build update request\") {\n        slog.Warn(\"googlechat: failed to build PATCH request; check chatAPIBase and message name\", \"error\", err)\n    }\n    return err\n}","preventionTips":["Validate chatAPIBase at config load time with url.Parse","Only use message names obtained verbatim from SendPreviewStart handles","Keep the context healthy (check ctx.Err() before issuing API calls)"],"tags":["googlechat","http","url","streaming-preview"],"backgroundTag":"invalid-url-format","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}