chenhg5/cc-connect · error
googlechat: invalid reply context type %T
Error message
googlechat: invalid reply context type %T
What it means
post expects the reply-context argument to be the platform's concrete replyContext struct (as produced by ReceiveMessage handling or ReconstructReplyCtx). This error is thrown when some other type is passed, meaning an engine or caller handed googlechat a reply context it did not create. It is an internal type-contract violation guard.
Source
Thrown at platform/googlechat/googlechat.go:416
// doRequest executes req using botClient and returns the response on success.
// On non-2xx it reads the error body, closes it, and returns an error.
// 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 {View on GitHub (pinned to 4000b2338a)
Solutions
- Ensure the reply context came from googlechat's own ReconstructReplyCtx (via the googlechat-prefixed session key), not another platform's
- Check session persistence so platform identity is preserved across restarts and /switch operations
- If writing custom code, use replyContext{space: "spaces/...", thread: "spaces/.../threads/..."} from the googlechat package
Example fix
// before
err := p.post(ctx, "spaces/AAAA", "hello") // string, wrong type
// after
rc, err := p.ReconstructReplyCtx("googlechat:spaces/AAAA")
if err != nil { return err }
err = p.post(ctx, rc, "hello") Defensive patterns
Strategy: type-guard
Validate before calling
if _, ok := rctx.(replyContext); !ok { return fmt.Errorf("googlechat: expected replyContext, got %T", rctx) } Type guard
func asGoogleChatReplyCtx(v any) (replyContext, bool) { rc, ok := v.(replyContext); return rc, ok } Try / catch
if err := p.post(ctx, rctx, content); err != nil {
if strings.Contains(err.Error(), "invalid reply context type") {
// context came from another platform; re-derive via ReconstructReplyCtx
rc, rerr := p.ReconstructReplyCtx(sessionKey)
...
}
} Prevention
- Never mix reply contexts between platform adapters; keep them platform-scoped
- Persist the platform name alongside the session key and route sends to the matching platform
- When writing custom send paths, always derive the context from that platform's ReconstructReplyCtx
When it happens
Trigger: Passing a reply context created by another platform (e.g. telegram's reply context), a raw string space name, or nil into post via Reply/Send or a custom integration.
Common situations: Cross-platform session switching where a session key was reconstructed by the wrong platform; custom code in cron or send-to-session features injecting hand-built context values; mixing core reply-context types across platform adapters.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- googlechat: marshal body: %w
- unknown validation error
- internal: unknown mode %q
- project %q located in parsed config but not raw file
- feishu/lark platform located in parsed config but not raw fi
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/82943f995a05503b.
Report an issue: GitHub.