chenhg5/cc-connect · error
%s: upload image: no image_key returned
Error message
%s: upload image: no image_key returned
What it means
The image upload call reported success but the response payload is missing the expected fields: uploadResp.Data is nil or Data.ImageKey is nil. This is an unexpected/empty API response — the library cannot proceed to send the image without the image_key, so it fails explicitly.
Source
Thrown at platform/feishu/feishu.go:3305
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)
if !ok {
return fmt.Errorf("%s: SendFile: invalid reply context type %T", p.tag(), rctx)
}
fileName := file.FileName
if fileName == "" {
fileName = "attachment"
}
fileType := detectFeishuFileType(file.MimeType, fileName)
var uploadResp *larkim.CreateFileResp
if err := p.withTransientRetry(ctx, "upload file", func() error {View on GitHub (pinned to 4000b2338a)
Solutions
- Log the full uploadResp (raw body/RequestId) when this occurs and report/compare against the SDK's response struct.
- Update the lark/oapi-sdk to the latest version to match current Feishu response shapes.
- Retry the upload once — transient empty responses are usually not reproducible.
- Add a defensive nil check and a clearer error including RequestId as this code already does.
Defensive patterns
Strategy: type-guard
Validate before calling
if uploadResp == nil || uploadResp.Data == nil || uploadResp.Data.ImageKey == nil {
return errors.New("feishu: image upload returned no image_key")
} Type guard
func hasImageKey(r *larkim.CreateImageResp) bool {
return r != nil && r.Data != nil && r.Data.ImageKey != nil
} Try / catch
key, err := uploadImage(ctx, data)
if errors.Is(err, errNoImageKey) {
// retry once, then report with RequestId
} Prevention
- Keep the lark/oapi-sdk dependency up to date.
- Nil-check Data/ImageKey before dereferencing.
- Log full raw response (RequestId) on empty payloads to aid Feishu support tickets.
When it happens
Trigger: uploadResp.Success() was true but Data/ImageKey are nil after the Im.Image.Create call at platform/feishu/feishu.go:3305 — typically an SDK version where the response struct field names changed, or Feishu returning an empty body on a 2xx.
Common situations: Outdated or mismatched github.com/larksuite/oapi-sdk version where ImageKey is not populated; Feishu-side incident returning 200 with empty body; proxy mangling the response.
Understand the failure class
Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.
Related errors
- %s: upload file: no file_key returned
- incomplete onboarding response
- %s: upload image: %w
- %s: upload image code=%d msg=%s
- %s: upload file: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/6707cf593c1f8c6c.
Report an issue: GitHub.