chenhg5/cc-connect · error
telegram: invalid preview handle type %T
Error message
telegram: invalid preview handle type %T
What it means
DeletePreviewMessage requires the previewHandle argument to be a *telegramPreviewHandle; this error is returned when it is not. Like the reply-context check, it is a contract violation caught at runtime via a type assertion, with %T exposing the offending type.
Source
Thrown at platform/telegram/telegram.go:1332
// Handle message too long: first chunk with buttons, rest without
slog.Warn("telegram: message too long, splitting into chunks",
"method", "SendWithButtons",
"html_len", len(html),
)
return p.sendChunkedWithButtons(ctx, bot, rc, html, rows)
}
if err != nil {
return fmt.Errorf("telegram: sendWithButtons: %w", err)
}
}
return nil
}
// DeletePreviewMessage deletes a stale preview message so the caller can send a fresh one.
func (p *Platform) DeletePreviewMessage(ctx context.Context, previewHandle any) error {
h, ok := previewHandle.(*telegramPreviewHandle)
if !ok {
return fmt.Errorf("telegram: invalid preview handle type %T", previewHandle)
}
bot, err := p.connectedBot("delete preview")
if err != nil {
return err
}
_, err = bot.DeleteMessage(ctx, &tgbot.DeleteMessageParams{ChatID: h.chatID, MessageID: h.messageID})
if err != nil {
slog.Debug("telegram: delete preview message failed", "error", err)
}
return err
}
func (p *Platform) downloadFile(fileID string) ([]byte, error) {
bot, err := p.connectedBot("download file")
if err != nil {
return nil, err
}
ctx := context.Background()View on GitHub (pinned to 4000b2338a)
Solutions
- Pass the *telegramPreviewHandle exactly as returned by the platform's preview-message send API.
- Fix the code path that produced the wrong handle type — check the %T output against platform/telegram's handle type.
- Keep platform-specific handles scoped to their platform's code paths.
- If handles cross a serialization boundary, store the chatID/messageID fields and rebuild the handle on this side.
Example fix
// before
platform.DeletePreviewMessage(ctx, genericHandle)
// after
h, ok := genericHandle.(*telegram.PreviewHandle)
if !ok { return fmt.Errorf("unexpected handle %T", genericHandle) }
platform.DeletePreviewMessage(ctx, h) Defensive patterns
Strategy: type-guard
Validate before calling
if handle == nil { return errors.New("nil preview handle") } Type guard
func asTelegramPreviewHandle(v any) (*telegramPreviewHandle, bool) {
h, ok := v.(*telegramPreviewHandle)
return h, ok
} Try / catch
h, ok := previewHandle.(*telegramPreviewHandle)
if !ok {
return fmt.Errorf("telegram: invalid preview handle type %T", previewHandle)
} Prevention
- Store preview handles per-platform, never in a shared cross-platform map
- Keep handles as opaque values and only pass them back to the creating platform
- Avoid serializing handles across process boundaries
- Log %T when handles come from dynamic sources
When it happens
Trigger: Calling p.DeletePreviewMessage(ctx, handle) with a handle produced by a different platform adapter, a plain struct copy instead of a pointer, or nil.
Common situations: Storing preview handles from multiple platforms in one map keyed by session and passing the wrong one; serializing/deserializing handles so the concrete pointer type is lost; passing the string message ID directly instead of the handle object.
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
- telegram: SendAudio: invalid reply context type %T
- bridge: invalid reply context type %T
- bridge: invalid reply context
- bridge: invalid preview handle
- dingtalk: SendAudio: invalid reply context type %T
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/684384962d2d8e82.
Report an issue: GitHub.