{"record":{"id":"b79230c80c5ae7b2","repo":"chenhg5/cc-connect","slug":"s-upload-file-no-file-key-returned","errorCode":null,"errorMessage":"%s: upload file: no file_key returned","messagePattern":"(.+?): upload file: no file_key returned","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/feishu/feishu.go","lineNumber":3346,"sourceCode":"\t\t\t\t\tFileName(fileName).\n\t\t\t\t\tFile(bytes.NewReader(file.Data)).\n\t\t\t\t\tBuild()).\n\t\t\t\tBuild()\n\t\t\tvar err error\n\t\t\tuploadResp, err = client.Im.File.Create(ctx, req, options...)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"%s: upload file: %w\", p.tag(), err)\n\t\t\t}\n\t\t\tif !uploadResp.Success() {\n\t\t\t\treturn fmt.Errorf(\"%s: upload file code=%d msg=%s\", p.tag(), uploadResp.Code, uploadResp.Msg)\n\t\t\t}\n\t\t\treturn nil\n\t\t})\n\t}); err != nil {\n\t\treturn err\n\t}\n\tif uploadResp.Data == nil || uploadResp.Data.FileKey == nil {\n\t\treturn fmt.Errorf(\"%s: upload file: no file_key returned\", p.tag())\n\t}\n\n\tmsgType := detectFeishuFileMessageType(fileType)\n\tfileContent, err := buildFeishuFileMessageContent(msgType, *uploadResp.Data.FileKey)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%s: build file message: %w\", p.tag(), err)\n\t}\n\n\treturn p.sendMediaMessage(ctx, rc, msgType, fileContent)\n}\n\nfunc (p *Platform) sendMediaMessage(ctx context.Context, rc replyContext, msgType, content string) error {\n\tif p.shouldUseThreadOrReplyAPI(rc) {\n\t\treturn p.replyMessage(ctx, rc, msgType, content)\n\t}\n\treturn p.createMessage(ctx, rc.chatID, msgType, content, \"send media message\")\n}\n","sourceCodeStart":3328,"sourceCodeEnd":3364,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/feishu/feishu.go#L3328-L3364","documentation":"The file upload reported success but uploadResp.Data or Data.FileKey is nil — the expected file_key is absent from an otherwise-successful response. Without file_key the library cannot build the file message, so it returns this explicit error.","triggerScenarios":"After Im.File.Create succeeds (Success()==true), Data==nil or Data.FileKey==nil at platform/feishu/feishu.go:3346 — empty response body on HTTP 200, or SDK response struct mismatch.","commonSituations":"SDK version drift (field renamed/missing), Feishu incident returning empty bodies, response truncated by a middle proxy.","solutions":["Log the raw response including RequestId when this happens and compare with the SDK struct.","Upgrade github.com/larksuite/oapi-sdk to the latest release.","Retry the upload once; transient empty responses usually succeed on retry.","Keep the existing nil guard so callers get this clear message rather than a nil dereference."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"if uploadResp == nil || uploadResp.Data == nil || uploadResp.Data.FileKey == nil {\n    return errors.New(\"feishu: file upload returned no file_key\")\n}","typeGuard":"func hasFileKey(r *larkim.CreateFileResp) bool {\n    return r != nil && r.Data != nil && r.Data.FileKey != nil\n}","tryCatchPattern":"err := p.SendFile(ctx, rc, file)\nif err != nil && strings.Contains(err.Error(), \"no file_key returned\") {\n    // retry upload once; escalate with RequestId if repeated\n}","preventionTips":["Keep the SDK version current with Feishu's response schema.","Always nil-check Data/FileKey before use.","Capture RequestId in logs for Feishu support escalation."],"tags":["feishu","upload","empty-response","sdk"],"backgroundTag":"unexpected-api-response-shape","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"}