chenhg5/cc-connect · error

%s: %s api call: %w

Error message

%s: %s api call: %w

What it means

Wraps a transport-level failure from the Lark SDK's Im.Message.Create call (sending a new message). Analogous to the reply-path error: the HTTP request itself failed before Feishu could return a business result, after transient and token-refresh retries were exhausted or deemed inapplicable.

Source

Thrown at platform/feishu/feishu.go:4078

			return nil
		})
	})
}

func (p *Platform) createMessage(ctx context.Context, chatID, msgType, content, op string) error {
	req := larkim.NewCreateMessageReqBuilder().
		ReceiveIdType(larkim.ReceiveIdTypeChatId).
		Body(larkim.NewCreateMessageReqBodyBuilder().
			ReceiveId(chatID).
			MsgType(msgType).
			Content(content).
			Build()).
		Build()
	return p.withTransientRetry(ctx, op, func() error {
		return p.withFreshTenantAccessTokenRetry(ctx, op, func(client *lark.Client, options ...larkcore.RequestOptionFunc) error {
			resp, err := client.Im.Message.Create(ctx, req, options...)
			if err != nil {
				return fmt.Errorf("%s: %s api call: %w", p.tag(), op, err)
			}
			if !resp.Success() {
				return fmt.Errorf("%s: %s failed code=%d msg=%s", p.tag(), op, resp.Code, resp.Msg)
			}
			return nil
		})
	})
}

func (p *Platform) withFreshTenantAccessTokenRetry(ctx context.Context, operation string, fn feishuRequestFunc) error {
	err := fn(p.client)
	if !isTenantAccessTokenInvalid(err) {
		return err
	}

	freshToken, refreshErr := p.fetchFreshTenantAccessToken(ctx)
	if refreshErr != nil {
		return fmt.Errorf("%s: %s failed after token refresh attempt: %w (original error: %v)", p.tag(), operation, refreshErr, err)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Inspect the wrapped error to distinguish network vs serialization causes.
  2. Test connectivity: curl https://open.feishu.cn from the host.
  3. Confirm receive_id_type and receive_id (chat_id) are valid in the request builder.
  4. Review withTransientRetry configuration if the failure is transient flakiness.
Defensive patterns

Strategy: retry

Validate before calling

if err := checkConnectivity("open.feishu.cn:443"); err != nil { /* defer send */ }

Try / catch

err := p.sendMessage(ctx, chatID, msgType, content)
if err != nil && errors.Is(err, context.DeadlineExceeded) {
	// retry once with longer timeout
}

Prevention

When it happens

Trigger: client.Im.Message.Create returns a non-nil error while sending a new message to a chat (receive_id=chat_id): network outage, DNS failure, TLS error, timeout, or request construction failure.

Common situations: Feishu API downtime, host without outbound internet access, proxy intercepting HTTPS, or invalid receive_id_type causing an SDK-level error.

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/d88d18c81b7c5cc3. Report an issue: GitHub.