chenhg5/cc-connect · error

%s: create card entity: parse response: %w

Error message

%s: create card entity: parse response: %w

What it means

The cardkit Create Card Entity API returned HTTP 200 but its RawBody could not be unmarshaled into the expected {code,msg,data:{card_id}} shape. Indicates the body is not the JSON the Cardkit v1 API documents — usually a gateway/auth page, truncated body, or an SDK RawBody issue.

Source

Thrown at platform/feishu/feishu.go:5187

	if err := p.withFreshTenantAccessTokenRetry(ctx, "create card entity", func(client *lark.Client, options ...larkcore.RequestOptionFunc) error {
		var err error
		apiResp, err = client.Post(ctx, "/open-apis/cardkit/v1/cards", body, larkcore.AccessTokenTypeTenant, options...)
		return err
	}); err != nil {
		return "", fmt.Errorf("%s: create card entity: %w", p.tag(), err)
	}
	if apiResp == nil || apiResp.StatusCode != http.StatusOK {
		return "", fmt.Errorf("%s: create card entity: HTTP status %d", p.tag(), apiResp.StatusCode)
	}
	var resp struct {
		Code int    `json:"code"`
		Msg  string `json:"msg"`
		Data struct {
			CardID string `json:"card_id"`
		} `json:"data"`
	}
	if err := json.Unmarshal(apiResp.RawBody, &resp); err != nil {
		return "", fmt.Errorf("%s: create card entity: parse response: %w", p.tag(), err)
	}
	if resp.Code != 0 {
		return "", fmt.Errorf("%s: %w", p.tag(), classifyFeishuCardAPIError("create card entity", resp.Code, resp.Msg))
	}
	if resp.Data.CardID == "" {
		return "", fmt.Errorf("%s: create card entity: empty card_id in response", p.tag())
	}
	return resp.Data.CardID, nil
}

// StreamRichCardText implements core.RichCardTextStreamer. Pushes the latest
// fullText to the rich card's main_text element via cardkit-v1 streaming text
// update API. The Lark client renders the increment between consecutive PUTs
// with a typewriter animation (controlled by the card's streaming_config).
//
// Returns ErrNotSupported when the handle has no cardID (preview was created
// via the inline-card-JSON fallback path; engine should fall back to full-card
// Patch).

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Log string(apiResp.RawBody) to see what was actually returned
  2. Verify the API base URL points to the real Feishu/Lark endpoint and no proxy rewrites it
  3. Upgrade the larksuite SDK so RawBody handling matches the current client
  4. If a Feishu schema change renamed fields, update the inline response struct

Example fix

// before
var resp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		CardID string `json:"card_id"`
	} `json:"data"`
}
// after
if len(apiResp.RawBody) == 0 {
	return "", fmt.Errorf("%s: create card entity: empty response body", p.tag())
}
var resp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		CardID string `json:"card_id"`
	} `json:"data"`
}
Defensive patterns

Strategy: validation

Validate before calling

if apiResp == nil || len(apiResp.RawBody) == 0 {
	return fmt.Errorf("empty cardkit response")
}
if apiResp.RawBody[0] != '{' {
	return fmt.Errorf("non-JSON cardkit response (proxy?)")
}

Try / catch

if err != nil {
	var unmarshalErr *json.UnmarshalTypeError
	if errors.As(err, &unmarshalErr) {
		// log RawBody; fall back to inline-card JSON send
	}
}

Prevention

When it happens

Trigger: json.Unmarshal(apiResp.RawBody, &resp) fails: the endpoint returned HTML (proxy login/error page), an empty body, or JSON whose data/card_id fields have incompatible types (e.g. card_id as a number).

Common situations: Corporate MITM proxy returning an auth page; misconfigured base URL pointing at a non-Feishu service; unexpected Feishu API version change altering response field types; truncated response from an aggressive intermediary.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


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