{"record":{"id":"357142361df6b3b6","repo":"chenhg5/cc-connect","slug":"s-upload-image-w","errorCode":null,"errorMessage":"%s: upload image: %w","messagePattern":"(.+?): upload image: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/feishu/feishu.go","lineNumber":3294,"sourceCode":"\t}\n\n\treturn p.sendMediaMessage(ctx, rc, larkim.MsgTypeImage, imageContent)\n}\n\nfunc (p *Platform) uploadImageKey(ctx context.Context, data []byte) (string, error) {\n\tvar uploadResp *larkim.CreateImageResp\n\tif err := p.withTransientRetry(ctx, \"upload image\", func() error {\n\t\treturn p.withFreshTenantAccessTokenRetry(ctx, \"upload image\", func(client *lark.Client, options ...larkcore.RequestOptionFunc) error {\n\t\t\treq := larkim.NewCreateImageReqBuilder().\n\t\t\t\tBody(larkim.NewCreateImageReqBodyBuilder().\n\t\t\t\t\tImageType(\"message\").\n\t\t\t\t\tImage(bytes.NewReader(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.Image.Create(ctx, req, options...)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"%s: upload image: %w\", p.tag(), err)\n\t\t\t}\n\t\t\tif !uploadResp.Success() {\n\t\t\t\treturn fmt.Errorf(\"%s: upload image 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.ImageKey == nil {\n\t\treturn \"\", fmt.Errorf(\"%s: upload image: no image_key returned\", p.tag())\n\t}\n\n\treturn *uploadResp.Data.ImageKey, nil\n}\n\nfunc (p *Platform) SendFile(ctx context.Context, rctx any, file core.FileAttachment) error {\n\trc, ok := rctx.(replyContext)","sourceCodeStart":3276,"sourceCodeEnd":3312,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/feishu/feishu.go#L3276-L3312","documentation":"Wraps a transport/API error from the Feishu SDK call client.Im.Image.Create, which uploads an image to Feishu to obtain an image_key. This library throws it because the upload request itself failed before a response was available (network error, auth failure, invalid request). The wrapped inner error carries the actual cause.","triggerScenarios":"client.Im.Image.Create returns a non-nil error inside the retry-wrapped upload block of the image upload helper (platform/feishu/feishu.go:3294), e.g. connection failure, expired tenant_access_token, or malformed request builder.","commonSituations":"Feishu API unreachable (proxy/firewall), app credentials invalid so token acquisition fails, oversized or unreadable image bytes, or SDK client misconfigured (bad AppID/AppSecret in config.toml).","solutions":["Inspect the wrapped inner error (%w) for the root cause (network vs auth vs 4xx).","Verify app_id/app_secret in config.toml are valid and the app has im:resource permission.","Check network connectivity / proxy settings to open.feishu.cn or open.larksuite.com.","Regenerate or refresh the tenant_access_token if it expired."],"exampleFix":"// before: only logging generic failure\nslog.Error(\"upload failed\")\n// after: unwrap and log cause\nif err != nil {\n    slog.Error(\"feishu image upload failed\", \"cause\", errors.Unwrap(err))\n}","handlingStrategy":"retry","validationCode":"if len(data) == 0 { return errors.New(\"empty image payload\") }\nif p.feishuClient == nil { return errors.New(\"feishu client not initialized\") }","typeGuard":null,"tryCatchPattern":"key, err := uploadImage(ctx, data)\nif err != nil {\n    var respErr *larkcore.APIError\n    if errors.As(err, &respErr) { /* handle API-level failure */ }\n    return fmt.Errorf(\"send image aborted: %w\", err)\n}","preventionTips":["Validate image bytes (non-empty, correct format, within size limits) before upload.","Keep app credentials and im:resource scope valid; run cc-connect doctor regularly.","Retry transient transport errors with exponential backoff."],"tags":["feishu","upload","network","api"],"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"}