{"record":{"id":"e2c3d09ca9f4e501","repo":"larksuite/cli","slug":"failed-to-parse-user-info-w","errorCode":null,"errorMessage":"failed to parse user info: %w","messagePattern":"failed to parse user info: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/auth/auth.go","lineNumber":95,"sourceCode":"\t\tOpenID string `json:\"open_id\"`\n\t\tName   string `json:\"name\"`\n\t} `json:\"data\"`\n}\n\n// getUserInfo fetches the current user's OpenID and name using the given access token.\nfunc getUserInfo(ctx context.Context, sdk *lark.Client, accessToken string) (openId, name string, err error) {\n\tapiResp, err := sdk.Do(ctx, &larkcore.ApiReq{\n\t\tHttpMethod:                http.MethodGet,\n\t\tApiPath:                   larkauth.PathUserInfoV1,\n\t\tSupportedAccessTokenTypes: []larkcore.AccessTokenType{larkcore.AccessTokenTypeUser},\n\t}, larkcore.WithUserAccessToken(accessToken))\n\tif err != nil {\n\t\treturn \"\", \"\", err\n\t}\n\n\tvar resp userInfoResponse\n\tif err := json.Unmarshal(apiResp.RawBody, &resp); err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to parse user info: %w\", err)\n\t}\n\tif resp.Code != 0 {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to get user info [%d]: %s\", resp.Code, resp.Msg)\n\t}\n\tif resp.Data.OpenID == \"\" {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to get user info: missing open_id in response\")\n\t}\n\n\tname = resp.Data.Name\n\tif name == \"\" {\n\t\tname = \"(unknown)\"\n\t}\n\treturn resp.Data.OpenID, name, nil\n}\n\n// appInfo contains application information (owner, scopes).\ntype appInfo struct {\n\tOwnerOpenId string","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/cmd/auth/auth.go#L77-L113","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the raw response body (enable SDK request/response logging or a proxy) to see what non-JSON payload was returned.","Verify the CLI is pointing at the correct Lark/Feishu gateway and no corporate proxy or captive portal is rewriting responses.","Retry the login; transient gateway errors often return non-JSON bodies.","Check for SDK/CLI version mismatch with the current authen/v1/user_info schema and update the CLI."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"openID, name, err := getUserInfo(ctx, client, token)\nif err != nil && strings.HasPrefix(err.Error(), \"failed to parse user info\") {\n    // non-JSON body: likely proxy/gateway interference\n    return fmt.Errorf(\"identity endpoint returned a non-JSON response; check network/proxy: %w\", err)\n}\nif err != nil { return err }","preventionTips":["Bypass corporate proxies/captive portals when authenticating","Retry once on parse failures; gateways intermittently inject HTML error pages","Keep the CLI/SDK updated to match the current user_info schema","Log raw response bodies on auth failures for diagnosis"],"tags":["json","auth","response-parsing","network"],"backgroundTag":"response-parse-failed","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}