{"record":{"id":"6ea3b1026d29e9e0","repo":"chenhg5/cc-connect","slug":"s-upload-file-w","errorCode":null,"errorMessage":"%s: upload file: %w","messagePattern":"(.+?): upload file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/feishu/feishu.go","lineNumber":3335,"sourceCode":"\tfileName := file.FileName\n\tif fileName == \"\" {\n\t\tfileName = \"attachment\"\n\t}\n\tfileType := detectFeishuFileType(file.MimeType, fileName)\n\tvar uploadResp *larkim.CreateFileResp\n\tif err := p.withTransientRetry(ctx, \"upload file\", func() error {\n\t\treturn p.withFreshTenantAccessTokenRetry(ctx, \"upload file\", func(client *lark.Client, options ...larkcore.RequestOptionFunc) error {\n\t\t\treq := larkim.NewCreateFileReqBuilder().\n\t\t\t\tBody(larkim.NewCreateFileReqBodyBuilder().\n\t\t\t\t\tFileType(fileType).\n\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}","sourceCodeStart":3317,"sourceCodeEnd":3353,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/feishu/feishu.go#L3317-L3353","documentation":"Wraps a transport/API error from client.Im.File.Create, which uploads a file to Feishu to obtain a file_key. Thrown when the request itself fails before a usable response is returned (network error, auth failure, request construction error). The underlying SDK error is wrapped with %w for cause inspection.","triggerScenarios":"client.Im.File.Create returns a non-nil error inside the retry-wrapped upload block of SendFile at platform/feishu/feishu.go:3335 — connection failure, invalid tenant token, or nil reader/empty FileType in the request builder.","commonSituations":"Invalid app credentials, missing im:resource scope causing token-scoped API rejection, uploading empty file.Data, or network/proxy problems reaching Feishu.","solutions":["Inspect the wrapped error for the root cause (auth vs network vs request).","Verify file.Data is non-empty and file.FileName/fileType are set sensibly before calling SendFile.","Check app permissions (im:resource) and credential validity in config.toml.","Test connectivity to open.feishu.cn / open.larksuite.com from the host."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if len(file.Data) == 0 { return errors.New(\"empty file payload\") }\nif len(file.Data) > 30*1024*1024 { return errors.New(\"file exceeds Feishu 30MB upload limit\") }","typeGuard":null,"tryCatchPattern":"if err := p.SendFile(ctx, rc, file); err != nil {\n    var apiErr *larkcore.APIError\n    if errors.As(err, &apiErr) { /* inspect Feishu code */ }\n    return fmt.Errorf(\"file send aborted: %w\", err)\n}","preventionTips":["Validate file size (<30MB) and non-empty data before calling SendFile.","Ensure im:resource scope is granted to the app.","Verify connectivity to the Feishu open API from the deployment host."],"tags":["feishu","upload","file","network"],"backgroundTag":"api-request-failed","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"}