{"record":{"id":"e4b7009992ccf8b9","repo":"chenhg5/cc-connect","slug":"googlechat-sendfile-invalid-reply-context-type","errorCode":null,"errorMessage":"googlechat: SendFile: invalid reply context type %T","messagePattern":"googlechat: SendFile: invalid reply context type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/googlechat/googlechat.go","lineNumber":577,"sourceCode":"// SendImage uploads an image and posts it as a Chat message attachment.\n// Implements core.ImageSender.\nfunc (p *Platform) SendImage(ctx context.Context, rctx any, img core.ImageAttachment) error {\n\trc, ok := rctx.(replyContext)\n\tif !ok {\n\t\treturn fmt.Errorf(\"googlechat: SendImage: invalid reply context type %T\", rctx)\n\t}\n\treturn p.postAttachment(ctx, rc,\n\t\tcoalesce(img.FileName, \"image.png\"),\n\t\tcoalesce(img.MimeType, \"image/png\"),\n\t\timg.Data)\n}\n\n// SendFile uploads a file and posts it as a Chat message attachment.\n// Implements core.FileSender.\nfunc (p *Platform) SendFile(ctx context.Context, rctx any, file core.FileAttachment) error {\n\trc, ok := rctx.(replyContext)\n\tif !ok {\n\t\treturn fmt.Errorf(\"googlechat: SendFile: invalid reply context type %T\", rctx)\n\t}\n\treturn p.postAttachment(ctx, rc,\n\t\tcoalesce(file.FileName, \"attachment\"),\n\t\tcoalesce(file.MimeType, \"application/octet-stream\"),\n\t\tfile.Data)\n}\n\nvar _ core.ImageSender = (*Platform)(nil)\nvar _ core.FileSender = (*Platform)(nil)\nvar _ core.ReplyContextReconstructor = (*Platform)(nil)\n\nfunc (p *Platform) Stop() error {\n\tif p.cancel != nil {\n\t\tp.cancel()\n\t}\n\tif p.psClient != nil {\n\t\treturn p.psClient.Close()\n\t}","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/googlechat/googlechat.go#L559-L595","documentation":"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.","triggerScenarios":"Calling SendFile with a reply context from another platform, nil, or a hand-rolled value that is not googlechat.replyContext.","commonSituations":"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.","solutions":["Pass the googlechat reply context that accompanied the original incoming message","Type-check the context at the call site before calling SendFile","Fix test mocks to construct the real replyContext type"],"exampleFix":"// before\np.SendFile(ctx, genericCtx, file)\n// after\nrc, ok := genericCtx.(googlechat.ReplyContext)\nif !ok { return fmt.Errorf(\"file send requires google chat reply context\") }\np.SendFile(ctx, rc, file)","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isGoogleChatReplyContext(rctx any) bool { _, ok := rctx.(replyContext); return ok }","tryCatchPattern":"if err := p.SendFile(ctx, rctx, file); err != nil {\n    if strings.Contains(err.Error(), \"invalid reply context type\") { slog.Error(\"SendFile got non-googlechat context\", \"type\", fmt.Sprintf(\"%T\", rctx)) }\n    return err\n}","preventionTips":["Keep per-platform context plumbing separate","Add compile-time interface assertions in adapters","Write tests that assert context type errors for cross-platform misuse"],"tags":["googlechat","type-mismatch","api-misuse"],"backgroundTag":"type-mismatch","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}