sipeed/picoclaw · error

feishu file upload: no file_key returned

Error message

feishu file upload: no file_key returned

What it means

The file upload reported Success()==true but Data or Data.FileKey is nil — an unexpected payload where the API claims success yet returns no file_key. A protocol deviation (gateway quirk or SDK response-shape mismatch), not an input error; nothing in the request is wrong.

Source

Thrown at pkg/channels/feishu/feishu_64.go:1212

	// Upload file to get file_key
	uploadReq := larkim.NewCreateFileReqBuilder().
		Body(larkim.NewCreateFileReqBodyBuilder().
			FileType(feishuFileType).
			FileName(filename).
			File(file).
			Build()).
		Build()

	uploadResp, err := c.client.Im.V1.File.Create(ctx, uploadReq)
	if err != nil {
		return fmt.Errorf("feishu file upload: %w", err)
	}
	if !uploadResp.Success() {
		c.invalidateTokenOnAuthError(uploadResp.Code)
		return fmt.Errorf("feishu file upload api error (code=%d msg=%s)", uploadResp.Code, uploadResp.Msg)
	}
	if uploadResp.Data == nil || uploadResp.Data.FileKey == nil {
		return fmt.Errorf("feishu file upload: no file_key returned")
	}

	fileKey := *uploadResp.Data.FileKey

	// Send file message
	content, _ := json.Marshal(map[string]string{"file_key": fileKey})
	req := larkim.NewCreateMessageReqBuilder().
		ReceiveIdType(larkim.CreateMessageV1ReceiveIDTypeChatId).
		Body(larkim.NewCreateMessageReqBodyBuilder().
			ReceiveId(chatID).
			MsgType(larkim.MsgTypeFile).
			Content(string(content)).
			Build()).
		Build()

	resp, err := c.client.Im.V1.Message.Create(ctx, req)
	if err != nil {
		return fmt.Errorf("feishu file send: %w", err)

View on GitHub (pinned to 49183d7e8d)

Solutions

  1. Retry the upload once — usually transient.
  2. Pin or upgrade the lark oapi SDK to a version aligned with the current Feishu response schema.
  3. Log the raw response body once to confirm data.file_key is truly absent (rules out SDK parsing).
  4. If reproducible, report to Feishu open-platform support with the request ID.
Defensive patterns

Strategy: retry

Type guard

func isMissingFileKey(err error) bool {
    return strings.Contains(err.Error(), "feishu file upload: no file_key returned")
}

Try / catch

if err := ch.SendMedia(ctx, msg); err != nil {
    if isMissingFileKey(err) {
        // retry the upload once; persistent recurrence points to SDK/API schema drift
    }
}

Prevention

When it happens

Trigger: Im.V1.File.Create succeeds with an empty data block; observed under Feishu gateway degradation or when the vendored lark SDK version parses the live response schema incorrectly.

Common situations: After an oapi-sdk-go version bump; during transient Feishu incidents; large-file edge cases hitting a partial gateway response.

Related errors


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/c87b9dfe3c29e43b. Report an issue: GitHub.