chenhg5/cc-connect · error

qq: SendFile: invalid reply context type %T

Error message

qq: SendFile: invalid reply context type %T

What it means

SendFile in the QQ platform only accepts a reply context of concrete type *replyContext (created internally by the platform when a message is received). If the caller passes anything else — nil, a context from another platform, or a value of the wrong type — it refuses with this type-assertion error naming the offending Go type.

Source

Thrown at platform/qq/qq.go:759

	}

	mime := resp.Header.Get("Content-Type")
	if mime == "" {
		mime = http.DetectContentType(data)
	}
	return data, mime, nil
}

// SendFile sends a file to the conversation.
// Implements core.FileSender.
//
// Uses base64-encoded file data to avoid file-path issues across
// Windows/WSL/Docker. Routes through NapCat HTTP API when configured
// (better for large files), falls back to WebSocket.
func (p *Platform) SendFile(ctx context.Context, replyCtx any, file core.FileAttachment) error {
	rctx, ok := replyCtx.(*replyContext)
	if !ok {
		return fmt.Errorf("qq: SendFile: invalid reply context type %T", replyCtx)
	}

	name := file.FileName
	if name == "" {
		name = "attachment"
	}

	b64data := "base64://" + base64.StdEncoding.EncodeToString(file.Data)

	// Pick API caller: prefer HTTP for large payloads, fall back to WebSocket.
	call := p.callAPI
	if p.httpURL != "" {
		call = p.callHTTPAPI
	}

	if rctx.messageType == "group" {
		_, err := call("upload_group_file", map[string]any{
			"group_id": rctx.groupID,

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Always pass the exact replyCtx value the engine handed you for a message received via the QQ platform — never construct one manually.
  2. Ensure each platform receives its own reply context; do not share contexts between QQ and other platform instances.
  3. Check the %T value in the error message to identify which wrong type was passed and trace where it came from.
  4. Nil-check the replyCtx before calling SendFile.

Example fix

// before
err := qqPlatform.SendFile(ctx, someOtherPlatformCtx, file) // wrong type
// after
if rctx, ok := replyCtx.(*qq.ReplyContext); ok {
	_ = qqPlatform.SendFile(ctx, rctx, file)
}
Defensive patterns

Strategy: type-guard

Validate before calling

if replyCtx == nil {
	return fmt.Errorf("no reply context")
}

Type guard

rctx, ok := replyCtx.(*replyContext)
if !ok {
	return fmt.Errorf("expected qq replyContext, got %T", replyCtx)
}

Try / catch

if err := qqPlatform.SendFile(ctx, replyCtx, file); err != nil {
	if strings.Contains(err.Error(), "invalid reply context type") {
		// you passed the wrong platform's context; re-route via the correct platform
	}
}

Prevention

When it happens

Trigger: Calling qq Platform.SendFile with a replyCtx that is not the *replyContext produced by this platform's message handling: a context built by hand, a context from a different platform adapter, or nil.

Common situations: Mixing reply contexts across platforms in custom automation code that fans one message out to several platforms. Passing nil because the caller had no reply context. Type changes after refactoring custom adapters.

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/2789ebb26a20d7dc. Report an issue: GitHub.