chenhg5/cc-connect · error

googlechat: missing space in reply context

Error message

googlechat: missing space in reply context

What it means

After confirming the reply context type, post validates that a target space is present, since every Chat API send URL is built from the space resource name. An empty space field means the replyContext is structurally valid but carries no destination, so sending is impossible and the error is returned before any HTTP request is made.

Source

Thrown at platform/googlechat/googlechat.go:419

// The caller is responsible for draining and closing resp.Body on success.
func (p *Platform) doRequest(req *http.Request) (*http.Response, error) {
	resp, err := p.botClient.Do(req)
	if err != nil {
		return nil, err
	}
	if resp.StatusCode >= 300 {
		return nil, httpErrorBody(resp, fmt.Sprintf("googlechat: %s %s", req.Method, req.URL.Path))
	}
	return resp, nil
}

func (p *Platform) post(ctx context.Context, rctx any, content string) error {
	rc, ok := rctx.(replyContext)
	if !ok {
		return fmt.Errorf("googlechat: invalid reply context type %T", rctx)
	}
	if rc.space == "" {
		return fmt.Errorf("googlechat: missing space in reply context")
	}
	url, body, err := buildSendRequest(rc, content)
	if err != nil {
		return err
	}
	req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body))
	if err != nil {
		return fmt.Errorf("googlechat: build 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 response body: %w", err)
	}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Verify the persisted session key contains a non-empty space after the "googlechat:" prefix (e.g. googlechat:spaces/AAAA)
  2. Delete/recreate the affected session so a fresh key is captured from a real inbound message
  3. Add a check on session-key save time to reject keys without a space resource name

Example fix

// before
key := "googlechat:t/xyz"           // empty space

// after
key := "googlechat:spaces/AAAA:t/xyz"
Defensive patterns

Strategy: validation

Validate before calling

func (rc replyContext) valid() bool { return strings.HasPrefix(rc.space, "spaces/") }

Try / catch

if err := p.Send(ctx, rc, msg); err != nil {
    if strings.Contains(err.Error(), "missing space") {
        slog.Warn("googlechat session has no space; dropping send", "key", sessionKey)
        return nil // or recreate the session
    }
}

Prevention

When it happens

Trigger: A replyContext constructed with an empty space — e.g. ReconstructReplyCtx given a key like "googlechat:" or "googlechat:t/foo" where nothing precedes the thread separator, or user-scoped key parsing yielding an empty space.

Common situations: Corrupted or truncated session keys stored by cron/send-to-session features; a session created before any space was known; hand-edited persisted session keys.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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