chenhg5/cc-connect · error
googlechat: parse create response
Error message
googlechat: parse create response: %w
What it means
This error wraps a JSON decoding failure that occurred while parsing the response body returned by the Google Chat API after posting the initial streaming-preview message (spaces.messages.create). The library throws it because the preview handle it returns is built from the message resource `name` field, so the response body must be valid JSON. If the body cannot be decoded as JSON, the platform cannot know whether the message was created and aborts SendPreviewStart.
Solutions
- Check that chatAPIBase / the configured Google Chat endpoint is correct (https://chat.googleapis.com/v1/) and that no proxy is rewriting responses
- Log the raw response body and HTTP status before decoding to see what was actually returned
- Verify the auth token is valid; re-run `cc-connect doctor` or refresh the service-account credentials
- Treat as transient and retry SendPreviewStart if the cause was a truncated/network response
Example fix
// before
decodeErr := json.NewDecoder(resp.Body).Decode(&msg)
// after: capture body for diagnostics on failure
raw, _ := io.ReadAll(resp.Body)
var msg struct{ Name string `json:"name"` }
if err := json.Unmarshal(raw, &msg); err != nil {
return nil, fmt.Errorf("googlechat: parse create response: %w (body: %.200s)", err, raw)
} Defensive patterns
Strategy: try-catch
Try / catch
handle, err := p.SendPreviewStart(ctx, rctx, initialText)
if err != nil {
if strings.Contains(err.Error(), "parse create response") {
slog.Warn("googlechat preview: non-JSON API response; check proxy/endpoint/auth", "error", err)
}
return fmt.Errorf("start streaming preview: %w", err)
} Prevention
- Use the default chatAPIBase endpoint; avoid proxies that inject HTML error pages
- Keep service-account credentials valid and rotated so auth failures return expected JSON
- Monitor network stability; retry transient truncations
When it happens
Trigger: json.NewDecoder(resp.Body).Decode(&msg) returns an error inside SendPreviewStart after p.doRequest succeeded: the response body is not valid JSON — e.g. an HTML error page from a proxy/gateway, a truncated response, an empty body, or a non-2xx response whose body is not JSON.
Common situations: Corporate proxies or API gateways returning HTML 502/504 pages with a 200-ish status line; network interruption mid-response causing a truncated body; pointing chatAPIBase at a wrong endpoint (config mistake) that returns non-JSON content; expired auth returning an unexpected non-JSON error payload.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- googlechat: build update request
- googlechat: create response missing message name
- googlechat: invalid preview handle type %T
- googlechat: marshal attachment body
- googlechat: marshal body
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/77fcef3b7e2cf5e8.
Report an issue: GitHub.
Appendix: source
Thrown at platform/googlechat/streaming.go:55
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body))
if err != nil {
return nil, fmt.Errorf("googlechat: build request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
resp, err := p.doRequest(req)
if err != nil {
return nil, fmt.Errorf("googlechat: send preview: %w", err)
}
defer func() {
if err := resp.Body.Close(); err != nil {
slog.Warn("googlechat: close preview response body", "error", err)
}
}()
var msg struct {
Name string `json:"name"`
}
if err := json.NewDecoder(resp.Body).Decode(&msg); err != nil {
return nil, fmt.Errorf("googlechat: parse create response: %w", err)
}
// drain any bytes json.Decoder left unread so the connection is reusable
_, _ = io.Copy(io.Discard, resp.Body)
if msg.Name == "" {
return nil, fmt.Errorf("googlechat: create response missing message name")
}
return &previewHandle{name: msg.Name}, nil
}
// buildUpdateRequest builds the PATCH URL and JSON body to update a message's text.
func buildUpdateRequest(msgName, content string) (string, []byte, error) {
u := chatAPIBase + msgName + "?updateMask=text"
b, err := json.Marshal(map[string]any{"text": content})
if err != nil {
return "", nil, fmt.Errorf("googlechat: marshal update body: %w", err)
}
return u, b, nil
}View on GitHub (pinned to 4000b2338a)