{"record":{"id":"dcd96dd1b3a6dfac","repo":"chenhg5/cc-connect","slug":"googlechat-sendimage-invalid-reply-context-type","errorCode":null,"errorMessage":"googlechat: SendImage: invalid reply context type %T","messagePattern":"googlechat: SendImage: invalid reply context type %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/googlechat/googlechat.go","lineNumber":564,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\tif _, err := io.Copy(io.Discard, resp.Body); err != nil {\n\t\t_ = resp.Body.Close()\n\t\treturn fmt.Errorf(\"googlechat: drain attachment create response body: %w\", err)\n\t}\n\tif err := resp.Body.Close(); err != nil {\n\t\treturn fmt.Errorf(\"googlechat: close attachment create response body: %w\", err)\n\t}\n\treturn nil\n}\n\n// 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)","sourceCodeStart":546,"sourceCodeEnd":582,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/googlechat/googlechat.go#L546-L582","documentation":"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.","triggerScenarios":"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.","commonSituations":"Mixing platform adapters in a multi-platform deployment; caching reply contexts across platforms; refactor changing the context type without updating callers.","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"],"exampleFix":"// before\np.SendImage(ctx, someOtherPlatformCtx, img)\n// after\nif gcCtx, ok := someOtherPlatformCtx.(googlechat.ReplyContext); ok {\n    p.SendImage(ctx, gcCtx, img)\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isGoogleChatReplyContext(rctx any) bool { _, ok := rctx.(replyContext); return ok }","tryCatchPattern":"if err := p.SendImage(ctx, rctx, img); err != nil {\n    var tErr *typeMismatchError\n    if errors.As(err, &tErr) { slog.Error(\"wrong reply context type\", \"got\", fmt.Sprintf(\"%T\", rctx)) }\n    return err\n}","preventionTips":["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"],"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"}