chenhg5/cc-connect · error
googlechat: SendImage: invalid reply context type %T
Error message
googlechat: SendImage: invalid reply context type %T
What it means
SendImage expects its reply-context argument to be the concrete type googlechat.replyContext. Because the core.ImageSender interface passes it as any, a context created by another platform (or any other value) fails the type assertion and triggers this error naming the offending dynamic type.
Source
Thrown at platform/googlechat/googlechat.go:564
if err != nil {
return err
}
if _, err := io.Copy(io.Discard, resp.Body); err != nil {
_ = resp.Body.Close()
return fmt.Errorf("googlechat: drain attachment create response body: %w", err)
}
if err := resp.Body.Close(); err != nil {
return fmt.Errorf("googlechat: close attachment create response body: %w", err)
}
return nil
}
// SendImage uploads an image and posts it as a Chat message attachment.
// Implements core.ImageSender.
func (p *Platform) SendImage(ctx context.Context, rctx any, img core.ImageAttachment) error {
rc, ok := rctx.(replyContext)
if !ok {
return fmt.Errorf("googlechat: SendImage: invalid reply context type %T", rctx)
}
return p.postAttachment(ctx, rc,
coalesce(img.FileName, "image.png"),
coalesce(img.MimeType, "image/png"),
img.Data)
}
// SendFile uploads a file and posts it as a Chat message attachment.
// Implements core.FileSender.
func (p *Platform) SendFile(ctx context.Context, rctx any, file core.FileAttachment) error {
rc, ok := rctx.(replyContext)
if !ok {
return fmt.Errorf("googlechat: SendFile: invalid reply context type %T", rctx)
}
return p.postAttachment(ctx, rc,
coalesce(file.FileName, "attachment"),
coalesce(file.MimeType, "application/octet-stream"),
file.Data)View on GitHub (pinned to 4000b2338a)
Solutions
- Only pass the reply context value returned by this googlechat platform (e.g. from Reply/message handling)
- Add a type assertion/check at the call site before invoking SendImage
- If writing cross-platform code, obtain rctx from the same platform instance you call SendImage on
Example fix
// before
p.SendImage(ctx, someOtherPlatformCtx, img)
// after
if gcCtx, ok := someOtherPlatformCtx.(googlechat.ReplyContext); ok {
p.SendImage(ctx, gcCtx, img)
} Defensive patterns
Strategy: type-guard
Type guard
func isGoogleChatReplyContext(rctx any) bool { _, ok := rctx.(replyContext); return ok } Try / catch
if err := p.SendImage(ctx, rctx, img); err != nil {
var tErr *typeMismatchError
if errors.As(err, &tErr) { slog.Error("wrong reply context type", "got", fmt.Sprintf("%T", rctx)) }
return err
} Prevention
- Never share reply contexts across platform adapters
- Obtain rctx from the same platform instance used for the send
- Type-check in generic multi-platform send helpers
When it happens
Trigger: Passing a reply context obtained from a different platform's adapter, a nil value, or a manually-built struct of the wrong type into SendImage.
Common situations: Mixing platform adapters in a multi-platform deployment; caching reply contexts across platforms; refactor changing the context type without updating callers.
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: SendFile: invalid reply context type %T
- dingtalk: SendImage: invalid reply context type %T
- googlechat: invalid reply context type %T
- max: unexpected replyCtx type %T
- qqbot: invalid reply context
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/dcd96dd1b3a6dfac.
Report an issue: GitHub.