chenhg5/cc-connect · error
%s: upload image: %w
Error message
%s: upload image: %w
What it means
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.
Source
Thrown at platform/feishu/feishu.go:3294
}
return p.sendMediaMessage(ctx, rc, larkim.MsgTypeImage, imageContent)
}
func (p *Platform) uploadImageKey(ctx context.Context, data []byte) (string, error) {
var uploadResp *larkim.CreateImageResp
if err := p.withTransientRetry(ctx, "upload image", func() error {
return p.withFreshTenantAccessTokenRetry(ctx, "upload image", func(client *lark.Client, options ...larkcore.RequestOptionFunc) error {
req := larkim.NewCreateImageReqBuilder().
Body(larkim.NewCreateImageReqBodyBuilder().
ImageType("message").
Image(bytes.NewReader(data)).
Build()).
Build()
var err error
uploadResp, err = client.Im.Image.Create(ctx, req, options...)
if err != nil {
return fmt.Errorf("%s: upload image: %w", p.tag(), err)
}
if !uploadResp.Success() {
return fmt.Errorf("%s: upload image code=%d msg=%s", p.tag(), uploadResp.Code, uploadResp.Msg)
}
return nil
})
}); err != nil {
return "", err
}
if uploadResp.Data == nil || uploadResp.Data.ImageKey == nil {
return "", fmt.Errorf("%s: upload image: no image_key returned", p.tag())
}
return *uploadResp.Data.ImageKey, nil
}
func (p *Platform) SendFile(ctx context.Context, rctx any, file core.FileAttachment) error {
rc, ok := rctx.(replyContext)View on GitHub (pinned to 4000b2338a)
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.
Example fix
// before: only logging generic failure
slog.Error("upload failed")
// after: unwrap and log cause
if err != nil {
slog.Error("feishu image upload failed", "cause", errors.Unwrap(err))
} Defensive patterns
Strategy: retry
Validate before calling
if len(data) == 0 { return errors.New("empty image payload") }
if p.feishuClient == nil { return errors.New("feishu client not initialized") } Try / catch
key, err := uploadImage(ctx, data)
if err != nil {
var respErr *larkcore.APIError
if errors.As(err, &respErr) { /* handle API-level failure */ }
return fmt.Errorf("send image aborted: %w", err)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- %s: upload file: %w
- api call: %w
- %s: upload audio: %w
- %s: upload video: %w
- %s: upload video: no file_key returned
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/357142361df6b3b6.
Report an issue: GitHub.