chenhg5/cc-connect · error

googlechat: missing space in reply context

Error message

googlechat: missing space in reply context

What it means

After the type assertion succeeds, SendPreviewStart still requires replyContext.space to be non-empty, because the preview message must be posted into a Chat space. An empty space fails fast with this message instead of issuing a doomed API call.

Source

Thrown at platform/googlechat/streaming.go:31

)

// previewHandle points at the in-flight streaming-preview message so
// UpdateMessage can patch it in place via spaces.messages.patch.
type previewHandle struct {
	name string // e.g. "spaces/AAA/messages/MMM"
}

// SendPreviewStart posts the initial streaming-preview message (threaded like a
// normal reply) and returns a handle for subsequent edits. Implements
// core.PreviewStarter; together with UpdateMessage it lights up the engine's
// real-time streaming preview for Google Chat.
func (p *Platform) SendPreviewStart(ctx context.Context, rctx any, content string) (any, error) {
	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)
		}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Populate replyContext.space from the incoming message's space resource name
  2. Disable streaming preview for conversations without a space, or fall back to plain replies
  3. Log the incoming message payload to confirm space metadata is present

Example fix

// before
rc := replyContext{} // no space
p.SendPreviewStart(ctx, rc, content)
// after
rc := replyContext{Space: msg.GetSpace().GetName()}
if rc.Space == "" { return errors.New("no space for preview") }
p.SendPreviewStart(ctx, rc, content)
Defensive patterns

Strategy: validation

Validate before calling

if rc, ok := rctx.(replyContext); !ok || rc.Space == "" { return errors.New("preview requires a google chat space") }

Type guard

func canStartPreview(rctx any) bool { rc, ok := rctx.(replyContext); return ok && rc.Space != "" }

Try / catch

if _, err := p.SendPreviewStart(ctx, rctx, content); err != nil {
    if strings.Contains(err.Error(), "missing space") { return fallbackToPlainReply(ctx, rctx, content) }
    return err
}

Prevention

When it happens

Trigger: A streaming preview is started for a conversation whose replyContext was built without a space name — e.g. DMs or webhook-sourced messages missing space metadata.

Common situations: Bot in chats where messages lack space.name; hand-constructed reply contexts omitting Space; upstream Chat API changes to message payloads.

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/b492fd4d03acae5f. Report an issue: GitHub.