chenhg5/cc-connect · info

googlechat: marshal update body: %w

Error message

googlechat: marshal update body: %w

What it means

This error wraps a json.Marshal failure while serializing the update body ({"text": content}) in buildUpdateRequest, which constructs the PATCH request for updating a streaming-preview message. json.Marshal of a map[string]any containing a single string value effectively cannot fail in practice, so this is a defensive branch. It is propagated verbatim from buildUpdateRequest to its callers (UpdateMessage and tests).

Source

Thrown at platform/googlechat/streaming.go:70

		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
}

// 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 {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. No action needed at runtime — this branch is effectively dead with a string-only body
  2. If you modified buildUpdateRequest, ensure all values in the body map are JSON-marshalable types
  3. Check the wrapped error message for the offending value's type if the branch does fire
Defensive patterns

Strategy: try-catch

Try / catch

if err != nil {
    return fmt.Errorf("update preview message: %w", err)
}

Prevention

When it happens

Trigger: json.Marshal(map[string]any{"text": content}) returns an error inside buildUpdateRequest. With the current body shape (one string value) this branch is practically unreachable; it would only trigger if the body construction were changed to include non-marshalable values (e.g. channels, funcs).

Common situations: Essentially none in production with the current code; developers modifying buildUpdateRequest to include unsupported value types would hit it. It may appear in test output when refactoring the function.

Understand the failure class

Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.

Related errors


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