chenhg5/cc-connect · error
googlechat: build update request: %w
Error message
googlechat: build update request: %w
What it means
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.
Source
Thrown at platform/googlechat/streaming.go:89
}
return u, b, nil
}
// UpdateMessage patches the preview message text in place. The engine passes the
// handle returned by SendPreviewStart (not the reply context). Implements
// core.MessageUpdater.
func (p *Platform) UpdateMessage(ctx context.Context, handle any, content string) error {
h, ok := handle.(*previewHandle)
if !ok {
return fmt.Errorf("googlechat: invalid preview handle type %T", handle)
}
url, body, err := buildUpdateRequest(h.name, content)
if err != nil {
return err
}
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, url, bytes.NewReader(body))
if err != nil {
return fmt.Errorf("googlechat: build update request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
resp, err := p.doRequest(req)
if err != nil {
return err
}
if _, err := io.Copy(io.Discard, resp.Body); err != nil {
_ = resp.Body.Close()
return fmt.Errorf("googlechat: drain update response body: %w", err)
}
if err := resp.Body.Close(); err != nil {
return fmt.Errorf("googlechat: close update response body: %w", err)
}
return nil
}
var (
_ core.MessageUpdater = (*Platform)(nil)View on GitHub (pinned to 4000b2338a)
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
Example fix
// before
u := chatAPIBase + msgName + "?updateMask=text"
// after: validate segments before building the URL
if strings.ContainsAny(msgName, " \t\r\n") {
return "", nil, fmt.Errorf("googlechat: invalid message name %q", msgName)
}
u := chatAPIBase + msgName + "?updateMask=text" Defensive patterns
Strategy: try-catch
Validate before calling
// validate config before starting the platform
if _, err := url.Parse(chatAPIBase); err != nil {
return fmt.Errorf("invalid googlechat chatAPIBase %q: %w", chatAPIBase, err)
} Try / catch
if err := p.UpdateMessage(ctx, handle, text); err != nil {
if strings.Contains(err.Error(), "build update request") {
slog.Warn("googlechat: failed to build PATCH request; check chatAPIBase and message name", "error", err)
}
return err
} Prevention
- 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)
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- googlechat: build request: %w
- googlechat: attachment message: build request: %w
- googlechat: build request: %w
- reasonix: create request: %w
- create request: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/fb04f4add23efc50.
Report an issue: GitHub.