{"record":{"id":"55ca314b76839ca1","repo":"chenhg5/cc-connect","slug":"s-build-file-message-w","errorCode":null,"errorMessage":"%s: build file message: %w","messagePattern":"(.+?): build file message: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/feishu/feishu.go","lineNumber":3352,"sourceCode":"\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\nfunc detectFeishuFileType(mimeType, fileName string) string {\n\tname := strings.ToLower(fileName)\n\tswitch {\n\tcase mimeType == \"application/pdf\" || strings.HasSuffix(name, \".pdf\"):\n\t\treturn larkim.FileTypePdf\n\tcase strings.HasSuffix(name, \".doc\") || strings.HasSuffix(name, \".docx\"):","sourceCodeStart":3334,"sourceCodeEnd":3370,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/feishu/feishu.go#L3334-L3370","documentation":"Wraps an error from buildFeishuFileMessageContent, which maps the detected Feishu message type (file/audio/media/opus etc.) and file_key into the JSON message content string. It fails when the file type is unsupported or content construction is invalid, and this wrapper adds the platform tag while preserving the cause.","triggerScenarios":"detectFeishuFileMessageType returned a type that buildFeishuFileMessageContent cannot serialize, or content marshalling failed, in SendFile at platform/feishu/feishu.go:3352.","commonSituations":"Sending a file with an unrecognized extension/fileType that maps to no supported message type; empty fileType combined with content that requires one; internal refactor leaving a msgType case unhandled.","solutions":["Set a supported FileType (e.g. \"file\", \"mp4\", \"opus\", \"pdf\") on the FileAttachment before sending.","Inspect the wrapped error from buildFeishuFileMessageContent for the exact unsupported type.","Add a case for the missing message type in buildFeishuFileMessageContent if you introduced a new one."],"exampleFix":"// before\ncore.FileAttachment{Data: data} // no type → unmapped msgType\n// after\ncore.FileAttachment{Data: data, FileName: \"report.pdf\", FileType: \"file\"}","handlingStrategy":"validation","validationCode":"switch strings.ToLower(fileType) {\ncase \"opus\", \"mp4\", \"pdf\", \"doc\", \"xls\", \"ppt\", \"stream\", \"file\", \"\":\n    // OK\ndefault:\n    return fmt.Errorf(\"unsupported file type %q\", fileType)\n}","typeGuard":null,"tryCatchPattern":"if err := p.SendFile(ctx, rc, file); err != nil {\n    if strings.Contains(err.Error(), \"build file message\") {\n        // fix FileType on the attachment and retry\n    }\n}","preventionTips":["Always populate FileType/FileName on FileAttachment with a supported value.","Add unit tests covering every msgType branch of buildFeishuFileMessageContent.","Default unknown types to \"file\" (stream) instead of failing."],"tags":["feishu","file","message-content","unsupported-type"],"backgroundTag":"unsupported-operation","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"}