chenhg5/cc-connect · error
%s: resource download requires non-empty messageID and fileK
Error message
%s: resource download requires non-empty messageID and fileKey
What it means
downloadResourceChunked refuses to run when messageID or fileKey is empty/whitespace. These values come from the inbound message envelope and are required to build the Feishu resource-download URL; the guard exists because the function itself documents that callers must pre-validate them.
Source
Thrown at platform/feishu/resource_download.go:77
// Behaviour:
// - Always issues a single Range bytes=0-0 GET first. If the server honours
// Range (206) we then loop the remaining chunks; if it doesn't (200) we
// already have the full body — done.
// - On any transient network error mid-loop: retries with exponential
// backoff up to maxTransientRetries before giving up.
//
// One GET is the minimum regardless of file size: small files return 200 and
// we are done; large files return 206 with the first chunk, then we loop.
// This avoids the wasted HEAD round-trip and keeps the "small file" path
// observable as exactly one outbound request, matching pre-#1741 behaviour
// for files under Feishu's streaming cap.
//
// messageID and fileKey come from the inbound message envelope; resType is
// the Feishu resource-type segment ("file", "image", ...). The caller MUST
// guarantee these have already been validated (no empty strings).
func (p *Platform) downloadResourceChunked(ctx context.Context, messageID, fileKey, resType string) ([]byte, error) {
if strings.TrimSpace(messageID) == "" || strings.TrimSpace(fileKey) == "" {
return nil, fmt.Errorf("%s: resource download requires non-empty messageID and fileKey", p.tag())
}
if p.resourceDownloadHTTP == nil {
// Defensive: callers running outside the normal constructor (notably
// unit tests that synthesise a Platform value) still get a sane
// client. We log instead of panicking so one stale test fixture
// doesn't crash the whole process.
slog.Warn(p.tag() + ": resourceDownloadHTTP is nil; using default client")
p.resourceDownloadHTTP = &http.Client{Timeout: 60 * time.Second}
}
if p.resourceChunkSize <= 0 {
p.resourceChunkSize = defaultResourceChunkSize()
}
if p.resourceMaxBytes <= 0 {
p.resourceMaxBytes = defaultResourceMaxBytes
}
token, err := p.fetchResourceTokenOrDefault(ctx)
if err != nil {View on GitHub (pinned to 4000b2338a)
Solutions
- Validate messageID and fileKey are non-empty at the call site before invoking downloadResource/downloadImage
- Inspect the inbound message envelope — the field was likely absent in the original message
- Trim whitespace and reject earlier in the message-parsing layer with a clearer error
- If the message legitimately lacks a fileKey, handle that message type separately instead of attempting a resource download
Example fix
// before
p.downloadResource(ctx, msgID, fileKey, "image")
// after
if strings.TrimSpace(msgID) == "" || strings.TrimSpace(fileKey) == "" {
return nil, fmt.Errorf("feishu: cannot download resource: empty messageID or fileKey")
}
p.downloadResource(ctx, msgID, fileKey, "image") Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(messageID) == "" || strings.TrimSpace(fileKey) == "" {
return fmt.Errorf("feishu: resource download needs non-empty messageID and fileKey")
} Try / catch
data, err := p.DownloadImage(ctx, msgID, fileKey)
if err != nil {
if strings.Contains(err.Error(), "non-empty messageID") {
// skip download; message lacked a usable key
}
} Prevention
- Validate envelope fields immediately after message parsing
- Trim identifiers before use
- Handle unsupported message types before attempting downloads
When it happens
Trigger: downloadImage/downloadResource called with an empty or whitespace-only messageID or fileKey — e.g. an inbound message missing an image key, or a caller passing zero-value strings.
Common situations: Upstream message parsing produced empty file_key (unsupported message type); caller forgot to trim/validate envelope fields; tests synthesizing Platform values with blank identifiers.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- app_id/app_secret are required
- invalid remote image URL
- invalid --platform-type %q, want feishu or lark
- unknown validation error
- decode response: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/14f8980b898fed99.
Report an issue: GitHub.