chenhg5/cc-connect · error

yuanbao: sign token response missing data

Error message

yuanbao: sign token response missing data

What it means

The sign-token API returned code 0 (success) but the data object was null, so no token could be extracted. This is a defensive invariant check against an upstream contract violation: a success code with no payload. It is returned immediately without retry.

Source

Thrown at platform/yuanbao/sign.go:185

				Token    string `json:"token"`
				BotID    string `json:"bot_id"`
				Duration int    `json:"duration"`
				Product  string `json:"product"`
				Source   string `json:"source"`
			} `json:"data"`
		}
		if err := json.Unmarshal(respBody, &result); err != nil {
			lastErr = fmt.Errorf("yuanbao: parse response: %w", err)
			continue
		}
		if result.Code == 10099 && attempt < maxRetries {
			continue
		}
		if result.Code != 0 {
			return nil, fmt.Errorf("yuanbao: sign token error code=%d", result.Code)
		}
		if result.Data == nil {
			return nil, fmt.Errorf("yuanbao: sign token response missing data")
		}
		return &tokenData{
			token: result.Data.Token, botID: result.Data.BotID,
			duration: result.Data.Duration, product: result.Data.Product,
			source: result.Data.Source,
		}, nil
	}
	return nil, lastErr
}

// VerifyCredentials probes the sign-token API with app_key/app_secret and
// returns the bot_id on success. Used by `cc-connect yuanbao setup` so users
// see a clear error before the platform starts retrying on a background loop.
func VerifyCredentials(appKey, appSecret, apiDomain, routeEnv string) (botID string, err error) {
	if strings.TrimSpace(appKey) == "" || strings.TrimSpace(appSecret) == "" {
		return "", fmt.Errorf("yuanbao: bot_token is required (format: app_key:app_secret)")
	}
	data, err := fetchToken(appKey, appSecret, apiDomain, routeEnv)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Capture the raw response body and report it to the yuanbao API team — code 0 with null data is a server-side contract violation.
  2. Retry the token fetch manually; if persistent, treat the endpoint as unhealthy and fall back.
  3. Verify no proxy/middleware is rewriting the JSON body between cc-connect and the sign service.
  4. Check for upstream API version changes that may have renamed the data field and update the struct in sign.go.
Defensive patterns

Strategy: fallback

Type guard

func hasTokenData(resp *tokenEnvelope) bool { return resp != nil && resp.Code == 0 && resp.Data != nil }

Try / catch

td, err := fetchToken(...)
if err != nil && strings.Contains(err.Error(), "missing data") {
    // treat endpoint as unhealthy: fall back to cached token or alert
}

Prevention

When it happens

Trigger: result.Data == nil after json.Unmarshal of a code==0 response — upstream returned {"code":0} with data omitted/null, typically a partial failure or protocol bug on the sign service.

Common situations: Upstream service degradation where the API reports success but omits the payload; an API version change that renamed the data field; a proxy stripping or rewriting the response body.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — 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/abf510e164188c13. Report an issue: GitHub.