chenhg5/cc-connect · error

googlechat: send preview: %w

Error message

googlechat: send preview: %w

What it means

Wraps an error from p.doRequest when actually sending the preview message POST to the Google Chat API. This covers transport-level failures: DNS, connection refused, TLS, timeouts, or cancelled context — not HTTP error statuses.

Source

Thrown at platform/googlechat/streaming.go:44

	rc, ok := rctx.(replyContext)
	if !ok {
		return nil, fmt.Errorf("googlechat: invalid reply context type %T", rctx)
	}
	if rc.space == "" {
		return nil, fmt.Errorf("googlechat: missing space in reply context")
	}
	url, body, err := buildSendRequest(rc, content)
	if err != nil {
		return nil, err
	}
	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

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Test egress connectivity: curl https://chat.googleapis.com from the host
  2. Check proxy env vars (HTTPS_PROXY) and TLS/CA configuration
  3. Retry the preview send; the engine's streaming flow is naturally retry-tolerant
  4. Increase context timeouts if previews fail on slow links
Defensive patterns

Strategy: retry

Try / catch

if _, err := p.SendPreviewStart(ctx, rc, content); err != nil {
    if errors.Is(err, context.DeadlineExceeded) || isTransientNetwork(err) {
        return retryWithBackoff(ctx, 3, func() error { _, err := p.SendPreviewStart(ctx, rc, content); return err })
    }
    return err
}

Prevention

When it happens

Trigger: Network outage or proxy blocking chat.googleapis.com; context deadline exceeded during slow networks; TLS certificate problems on the host.

Common situations: Firewalled servers without egress to Google APIs; DNS misconfiguration; expired system CA bundles; long-running streams on flaky networks.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/aaf9df336040f38d. Report an issue: GitHub.