chenhg5/cc-connect · error
%s: SendFile: invalid reply context type %T
Error message
%s: SendFile: invalid reply context type %T
What it means
SendFile type-asserts its rctx parameter to the platform-internal replyContext type; the assertion failed, meaning the caller passed a reply context from a different platform or a non-context value. This is an internal programming/contract error, not an API failure.
Source
Thrown at platform/feishu/feishu.go:3314
if !uploadResp.Success() {
return fmt.Errorf("%s: upload image code=%d msg=%s", p.tag(), uploadResp.Code, uploadResp.Msg)
}
return nil
})
}); err != nil {
return "", err
}
if uploadResp.Data == nil || uploadResp.Data.ImageKey == nil {
return "", fmt.Errorf("%s: upload image: no image_key returned", p.tag())
}
return *uploadResp.Data.ImageKey, nil
}
func (p *Platform) SendFile(ctx context.Context, rctx any, file core.FileAttachment) error {
rc, ok := rctx.(replyContext)
if !ok {
return fmt.Errorf("%s: SendFile: invalid reply context type %T", p.tag(), rctx)
}
fileName := file.FileName
if fileName == "" {
fileName = "attachment"
}
fileType := detectFeishuFileType(file.MimeType, fileName)
var uploadResp *larkim.CreateFileResp
if err := p.withTransientRetry(ctx, "upload file", func() error {
return p.withFreshTenantAccessTokenRetry(ctx, "upload file", func(client *lark.Client, options ...larkcore.RequestOptionFunc) error {
req := larkim.NewCreateFileReqBuilder().
Body(larkim.NewCreateFileReqBodyBuilder().
FileType(fileType).
FileName(fileName).
File(bytes.NewReader(file.Data)).
Build()).
Build()
var err errorView on GitHub (pinned to 4000b2338a)
Solutions
- Ensure SendFile is only called with the replyContext produced by the same feishu Platform instance's Reply/消息 handling path.
- Do not cache replyContext values across platform restarts; re-derive from the incoming message.
- If bridging platforms, re-create the correct platform's context instead of forwarding the wrong one.
Example fix
// before crossPlatform.ReplyCtx = telegramCtx feishu.SendFile(ctx, crossPlatform.ReplyCtx, file) // panics into this error // after feishu.SendFile(ctx, feishuReplyCtxFromMessage, file)
Defensive patterns
Strategy: type-guard
Validate before calling
if _, ok := rctx.(feishu.replyContext); !ok {
return errors.New("SendFile requires a feishu replyContext")
} Type guard
func isFeishuReplyContext(rc any) bool {
_, ok := rc.(replyContext)
return ok
} Try / catch
if err := p.SendFile(ctx, rc, file); err != nil {
if strings.Contains(err.Error(), "invalid reply context type") {
// caller passed wrong platform's context; fix routing
}
} Prevention
- Never forward reply contexts between different platform adapters.
- Derive replyContext fresh from the current incoming message, not from caches.
- Keep replyContext unexported so other packages cannot construct or confuse it.
When it happens
Trigger: Calling feishu Platform.SendFile with rctx not created by this feishu platform (e.g. a replyContext from telegram, a raw message ID string, or nil) at platform/feishu/feishu.go:3314.
Common situations: Routing an engine send across platforms with the wrong platform's reply context; caching a replyContext from a removed/re-created platform instance; tests passing a mock context.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- %s: invalid reply context type %T
- %s: StreamRichCardText: invalid preview handle type %T
- %s: SendAudio: invalid reply context type %T
- %s: SendVideo: invalid reply context type %T
- app_id/app_secret are required
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/ed3fe063d133e87c.
Report an issue: GitHub.