larksuite/cli · error

failed to parse user info: %w

Error message

failed to parse user info: %w

What it means

In cmd/auth getUserInfo, after a successful call to /open-apis/authen/v1/user_info, the raw body is unmarshaled into userInfoResponse; if json.Unmarshal fails, the error is wrapped as 'failed to parse user info: %w'. It indicates the identity service returned a body that is not the expected JSON envelope. Note this is a plain fmt.Errorf wrap, not a typed errs.* error per the repository error contract.

Source

Thrown at cmd/auth/auth.go:95

		OpenID string `json:"open_id"`
		Name   string `json:"name"`
	} `json:"data"`
}

// getUserInfo fetches the current user's OpenID and name using the given access token.
func getUserInfo(ctx context.Context, sdk *lark.Client, accessToken string) (openId, name string, err error) {
	apiResp, err := sdk.Do(ctx, &larkcore.ApiReq{
		HttpMethod:                http.MethodGet,
		ApiPath:                   larkauth.PathUserInfoV1,
		SupportedAccessTokenTypes: []larkcore.AccessTokenType{larkcore.AccessTokenTypeUser},
	}, larkcore.WithUserAccessToken(accessToken))
	if err != nil {
		return "", "", err
	}

	var resp userInfoResponse
	if err := json.Unmarshal(apiResp.RawBody, &resp); err != nil {
		return "", "", fmt.Errorf("failed to parse user info: %w", err)
	}
	if resp.Code != 0 {
		return "", "", fmt.Errorf("failed to get user info [%d]: %s", resp.Code, resp.Msg)
	}
	if resp.Data.OpenID == "" {
		return "", "", fmt.Errorf("failed to get user info: missing open_id in response")
	}

	name = resp.Data.Name
	if name == "" {
		name = "(unknown)"
	}
	return resp.Data.OpenID, name, nil
}

// appInfo contains application information (owner, scopes).
type appInfo struct {
	OwnerOpenId string

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Inspect the raw response body (enable SDK request/response logging or a proxy) to see what non-JSON payload was returned.
  2. Verify the CLI is pointing at the correct Lark/Feishu gateway and no corporate proxy or captive portal is rewriting responses.
  3. Retry the login; transient gateway errors often return non-JSON bodies.
  4. Check for SDK/CLI version mismatch with the current authen/v1/user_info schema and update the CLI.
Defensive patterns

Strategy: try-catch

Try / catch

openID, name, err := getUserInfo(ctx, client, token)
if err != nil && strings.HasPrefix(err.Error(), "failed to parse user info") {
    // non-JSON body: likely proxy/gateway interference
    return fmt.Errorf("identity endpoint returned a non-JSON response; check network/proxy: %w", err)
}
if err != nil { return err }

Prevention

When it happens

Trigger: sdk.Do succeeds at transport level but apiResp.RawBody is not valid JSON for userInfoResponse — e.g. an HTML error page from a proxy/gateway, a truncated response, or a field type mismatch (non-integer `code`, non-string `msg`) against the userInfoResponse struct.

Common situations: Corporate proxy or captive portal injecting HTML into the response; hitting the wrong base URL endpoint; gateway 502 pages returned with 200; changes in the authen API response schema.

Understand the failure class

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/e2c3d09ca9f4e501. Report an issue: GitHub.