chenhg5/cc-connect · error
%s: build file message: %w
Error message
%s: build file message: %w
What it means
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.
Source
Thrown at platform/feishu/feishu.go:3352
if err != nil {
return fmt.Errorf("%s: upload file: %w", p.tag(), err)
}
if !uploadResp.Success() {
return fmt.Errorf("%s: upload file code=%d msg=%s", p.tag(), uploadResp.Code, uploadResp.Msg)
}
return nil
})
}); err != nil {
return err
}
if uploadResp.Data == nil || uploadResp.Data.FileKey == nil {
return fmt.Errorf("%s: upload file: no file_key returned", p.tag())
}
msgType := detectFeishuFileMessageType(fileType)
fileContent, err := buildFeishuFileMessageContent(msgType, *uploadResp.Data.FileKey)
if err != nil {
return fmt.Errorf("%s: build file message: %w", p.tag(), err)
}
return p.sendMediaMessage(ctx, rc, msgType, fileContent)
}
func (p *Platform) sendMediaMessage(ctx context.Context, rc replyContext, msgType, content string) error {
if p.shouldUseThreadOrReplyAPI(rc) {
return p.replyMessage(ctx, rc, msgType, content)
}
return p.createMessage(ctx, rc.chatID, msgType, content, "send media message")
}
func detectFeishuFileType(mimeType, fileName string) string {
name := strings.ToLower(fileName)
switch {
case mimeType == "application/pdf" || strings.HasSuffix(name, ".pdf"):
return larkim.FileTypePdf
case strings.HasSuffix(name, ".doc") || strings.HasSuffix(name, ".docx"):View on GitHub (pinned to 4000b2338a)
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.
Example fix
// before
core.FileAttachment{Data: data} // no type → unmapped msgType
// after
core.FileAttachment{Data: data, FileName: "report.pdf", FileType: "file"} Defensive patterns
Strategy: validation
Validate before calling
switch strings.ToLower(fileType) {
case "opus", "mp4", "pdf", "doc", "xls", "ppt", "stream", "file", "":
// OK
default:
return fmt.Errorf("unsupported file type %q", fileType)
} Try / catch
if err := p.SendFile(ctx, rc, file); err != nil {
if strings.Contains(err.Error(), "build file message") {
// fix FileType on the attachment and retry
}
} Prevention
- 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.
When it happens
Trigger: detectFeishuFileMessageType returned a type that buildFeishuFileMessageContent cannot serialize, or content marshalling failed, in SendFile at platform/feishu/feishu.go:3352.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- %s: upload file: %w
- %s: upload file code=%d msg=%s
- app_id/app_secret are required
- invalid remote image URL
- too many redirects
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/55ca314b76839ca1.
Report an issue: GitHub.