{"record":{"id":"e5b3d1f91f58afae","repo":"larksuite/cli","slug":"failed-to-get-user-info-d-s","errorCode":null,"errorMessage":"failed to get user info [%d]: %s","messagePattern":"failed to get user info \\[(.+?)\\]: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/auth/auth.go","lineNumber":98,"sourceCode":"}\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\n\tUserScopes  []string\n}\n","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/cmd/auth/auth.go#L80-L116","documentation":"getUserInfo returns 'failed to get user info [%d]: %s' when the /open-apis/authen/v1/user_info endpoint responds with a well-formed envelope whose code field is non-zero, meaning the identity API itself rejected the request. The numeric code and msg come straight from the API response. This is a plain fmt.Errorf, not a typed errs.* API error wrapper per the repository error contract.","triggerScenarios":"Any non-zero code from user_info: most commonly invalid/expired user_access_token (e.g. code 99991663/99991661-style token errors), insufficient scope for authen user_info, or app-configuration problems; raised during `auth login` flows (authLoginRun, authLoginPollDeviceCode) right after obtaining the token.","commonSituations":"User access token expired between token exchange and user_info call; the app lacks the required authen scopes; wrong tenant/app credentials configured; token type mismatch (using tenant token where user token is required).","solutions":["Read the bracketed code and msg in the error, then look it up in Lark's API error code documentation to identify the exact cause.","Rerun `lark-cli auth login` to obtain a fresh user access token; expired tokens are the most common cause.","Verify the app has the necessary authen/user_info scopes granted in the developer console.","Check app_id/app_secret configuration for the active profile; misconfiguration surfaces as API-side rejection codes."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"openID, name, err := getUserInfo(ctx, client, token)\nif err != nil {\n    var apiErr *larkcore.ApiError // or inspect the bracketed code in the message\n    // match 'failed to get user info [code]: msg' and route on code\n    if strings.Contains(err.Error(), \"failed to get user info [99991\") {\n        return fmt.Errorf(\"user token invalid or expired; run 'lark-cli auth login' again: %w\", err)\n    }\n    return err\n}","preventionTips":["Re-run `lark-cli auth login` when tokens may have expired","Grant the app the required authen/user_info scopes in the developer console","Verify app_id/app_secret for the active profile before login","Look up the exact bracketed code in Lark's error-code docs before changing code"],"tags":["auth","api-error","token","user-info"],"backgroundTag":"lark-api-error-code","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"}