chenhg5/cc-connect · error

googlechat: SendFile: invalid reply context type %T

Error message

googlechat: SendFile: invalid reply context type %T

What it means

SendFile, like SendImage, requires a googlechat.replyContext as its reply-context argument; any other dynamic type passed through the core.FileSender interface fails the assertion and produces this error, which includes the offending type for diagnosis.

Solutions

  1. Pass the googlechat reply context that accompanied the original incoming message
  2. Type-check the context at the call site before calling SendFile
  3. Fix test mocks to construct the real replyContext type

Example fix

// before
p.SendFile(ctx, genericCtx, file)
// after
rc, ok := genericCtx.(googlechat.ReplyContext)
if !ok { return fmt.Errorf("file send requires google chat reply context") }
p.SendFile(ctx, rc, file)
Defensive patterns

Strategy: type-guard

Type guard

func isGoogleChatReplyContext(rctx any) bool { _, ok := rctx.(replyContext); return ok }

Try / catch

if err := p.SendFile(ctx, rctx, file); err != nil {
    if strings.Contains(err.Error(), "invalid reply context type") { slog.Error("SendFile got non-googlechat context", "type", fmt.Sprintf("%T", rctx)) }
    return err
}

Prevention

When it happens

Trigger: Calling SendFile with a reply context from another platform, nil, or a hand-rolled value that is not googlechat.replyContext.

Common situations: Shared sending code reusing one context struct for all platforms; wiring bugs in multi-platform setups; tests passing a mock context of the wrong type.

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


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

Appendix: source

Thrown at platform/googlechat/googlechat.go:577

// 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)
}

var _ core.ImageSender = (*Platform)(nil)
var _ core.FileSender = (*Platform)(nil)
var _ core.ReplyContextReconstructor = (*Platform)(nil)

func (p *Platform) Stop() error {
	if p.cancel != nil {
		p.cancel()
	}
	if p.psClient != nil {
		return p.psClient.Close()
	}

View on GitHub (pinned to 4000b2338a)