chenhg5/cc-connect · error

%s: upload file: %w

Error message

%s: upload file: %w

What it means

Wraps a transport/API error from client.Im.File.Create, which uploads a file to Feishu to obtain a file_key. Thrown when the request itself fails before a usable response is returned (network error, auth failure, request construction error). The underlying SDK error is wrapped with %w for cause inspection.

Source

Thrown at platform/feishu/feishu.go:3335

	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 {
		return p.withFreshTenantAccessTokenRetry(ctx, "upload file", func(client *lark.Client, options ...larkcore.RequestOptionFunc) error {
			req := larkim.NewCreateFileReqBuilder().
				Body(larkim.NewCreateFileReqBodyBuilder().
					FileType(fileType).
					FileName(fileName).
					File(bytes.NewReader(file.Data)).
					Build()).
				Build()
			var err error
			uploadResp, err = client.Im.File.Create(ctx, req, options...)
			if err != nil {
				return fmt.Errorf("%s: upload file: %w", p.tag(), err)
			}
			if !uploadResp.Success() {
				return fmt.Errorf("%s: upload file code=%d msg=%s", p.tag(), uploadResp.Code, uploadResp.Msg)
			}
			return nil
		})
	}); err != nil {
		return err
	}
	if uploadResp.Data == nil || uploadResp.Data.FileKey == nil {
		return fmt.Errorf("%s: upload file: no file_key returned", p.tag())
	}

	msgType := detectFeishuFileMessageType(fileType)
	fileContent, err := buildFeishuFileMessageContent(msgType, *uploadResp.Data.FileKey)
	if err != nil {
		return fmt.Errorf("%s: build file message: %w", p.tag(), err)
	}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Inspect the wrapped error for the root cause (auth vs network vs request).
  2. Verify file.Data is non-empty and file.FileName/fileType are set sensibly before calling SendFile.
  3. Check app permissions (im:resource) and credential validity in config.toml.
  4. Test connectivity to open.feishu.cn / open.larksuite.com from the host.
Defensive patterns

Strategy: validation

Validate before calling

if len(file.Data) == 0 { return errors.New("empty file payload") }
if len(file.Data) > 30*1024*1024 { return errors.New("file exceeds Feishu 30MB upload limit") }

Try / catch

if err := p.SendFile(ctx, rc, file); err != nil {
    var apiErr *larkcore.APIError
    if errors.As(err, &apiErr) { /* inspect Feishu code */ }
    return fmt.Errorf("file send aborted: %w", err)
}

Prevention

When it happens

Trigger: client.Im.File.Create returns a non-nil error inside the retry-wrapped upload block of SendFile at platform/feishu/feishu.go:3335 — connection failure, invalid tenant token, or nil reader/empty FileType in the request builder.

Common situations: Invalid app credentials, missing im:resource scope causing token-scoped API rejection, uploading empty file.Data, or network/proxy problems reaching Feishu.

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


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/6ea3b1026d29e9e0. Report an issue: GitHub.