{"record":{"id":"2789ebb26a20d7dc","repo":"chenhg5/cc-connect","slug":"qq-sendfile-invalid-reply-context-type-t","errorCode":null,"errorMessage":"qq: SendFile: invalid reply context type %T","messagePattern":"qq: SendFile: invalid reply context type %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/qq/qq.go","lineNumber":759,"sourceCode":"\t}\n\n\tmime := resp.Header.Get(\"Content-Type\")\n\tif mime == \"\" {\n\t\tmime = http.DetectContentType(data)\n\t}\n\treturn data, mime, nil\n}\n\n// SendFile sends a file to the conversation.\n// Implements core.FileSender.\n//\n// Uses base64-encoded file data to avoid file-path issues across\n// Windows/WSL/Docker. Routes through NapCat HTTP API when configured\n// (better for large files), falls back to WebSocket.\nfunc (p *Platform) SendFile(ctx context.Context, replyCtx any, file core.FileAttachment) error {\n\trctx, ok := replyCtx.(*replyContext)\n\tif !ok {\n\t\treturn fmt.Errorf(\"qq: SendFile: invalid reply context type %T\", replyCtx)\n\t}\n\n\tname := file.FileName\n\tif name == \"\" {\n\t\tname = \"attachment\"\n\t}\n\n\tb64data := \"base64://\" + base64.StdEncoding.EncodeToString(file.Data)\n\n\t// Pick API caller: prefer HTTP for large payloads, fall back to WebSocket.\n\tcall := p.callAPI\n\tif p.httpURL != \"\" {\n\t\tcall = p.callHTTPAPI\n\t}\n\n\tif rctx.messageType == \"group\" {\n\t\t_, err := call(\"upload_group_file\", map[string]any{\n\t\t\t\"group_id\": rctx.groupID,","sourceCodeStart":741,"sourceCodeEnd":777,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/qq/qq.go#L741-L777","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Always pass the exact replyCtx value the engine handed you for a message received via the QQ platform — never construct one manually.","Ensure each platform receives its own reply context; do not share contexts between QQ and other platform instances.","Check the %T value in the error message to identify which wrong type was passed and trace where it came from.","Nil-check the replyCtx before calling SendFile."],"exampleFix":"// before\nerr := qqPlatform.SendFile(ctx, someOtherPlatformCtx, file) // wrong type\n// after\nif rctx, ok := replyCtx.(*qq.ReplyContext); ok {\n\t_ = qqPlatform.SendFile(ctx, rctx, file)\n}","handlingStrategy":"type-guard","validationCode":"if replyCtx == nil {\n\treturn fmt.Errorf(\"no reply context\")\n}","typeGuard":"rctx, ok := replyCtx.(*replyContext)\nif !ok {\n\treturn fmt.Errorf(\"expected qq replyContext, got %T\", replyCtx)\n}","tryCatchPattern":"if err := qqPlatform.SendFile(ctx, replyCtx, file); err != nil {\n\tif strings.Contains(err.Error(), \"invalid reply context type\") {\n\t\t// you passed the wrong platform's context; re-route via the correct platform\n\t}\n}","preventionTips":["Never hand-construct reply contexts; only use values delivered by the engine's message events.","Keep one reply context per platform instance; do not share across adapters.","Add a unit test asserting SendFile rejects foreign context types."],"tags":["type-error","qq","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-14T05:17:10.506Z"}