{"record":{"id":"fa0797abd0a49739","repo":"anuraghazra/github-readme-stats","slug":"user-not-found-fa0797","errorCode":"USER_NOT_FOUND","errorMessage":"Could not fetch user.","messagePattern":"Could not fetch user\\.","errorType":"error_code","errorClass":"CustomError","httpStatus":null,"severity":"error","filePath":"src/fetchers/top-languages.js","lineNumber":77,"sourceCode":" * @param {number} count_weight Weightage to be given to count.\n * @returns {Promise<TopLangData>} Top languages data.\n */\nconst fetchTopLanguages = async (\n  username,\n  exclude_repo = [],\n  size_weight = 1,\n  count_weight = 0,\n) => {\n  if (!username) {\n    throw new MissingParamError([\"username\"]);\n  }\n\n  const res = await retryer(fetcher, { login: username });\n\n  if (res.data.errors) {\n    logger.error(res.data.errors);\n    if (res.data.errors[0].type === \"NOT_FOUND\") {\n      throw new CustomError(\n        res.data.errors[0].message || \"Could not fetch user.\",\n        CustomError.USER_NOT_FOUND,\n      );\n    }\n    if (res.data.errors[0].message) {\n      throw new CustomError(\n        wrapTextMultiline(res.data.errors[0].message, 90, 1)[0],\n        res.statusText,\n      );\n    }\n    throw new CustomError(\n      \"Something went wrong while trying to retrieve the language data using the GraphQL API.\",\n      CustomError.GRAPHQL_ERROR,\n    );\n  }\n\n  let repoNodes = res.data.data.user.repositories.nodes;\n  /** @type {Record<string, boolean>} */","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/anuraghazra/github-readme-stats/blob/54a7985aeefda00d5eadb55b80c17c7f976c37d2/src/fetchers/top-languages.js#L59-L95","documentation":"Raised when GitHub's GraphQL API returns a top-level errors array whose first entry has type \"NOT_FOUND\" and no message field. The literal \"Could not fetch user.\" is only the fallback; if the GraphQL entry carries a message it is used instead. The accompanying secondary message (src/common/error.js:16) is \"Make sure the provided username is not an organization\", which is the real hint: the fetcher queries `user(login:)`, not `organization(login:)`, so orgs and non-user accounts cannot be resolved.","triggerScenarios":"The retryer returns a response whose res.data.errors[0].type === \"NOT_FOUND\". Concretely: the login does not correspond to any GitHub user account (typo, renamed account, deleted user), or the login belongs to an organization (the `user(login: ...)` field yields null and GitHub emits a NOT_FOUND error). RATE_LIMITED errors are filtered out earlier by the retryer, so they never reach this branch.","commonSituations":"Passing an organization name (e.g. a company account) where a personal user login is expected; a renamed GitHub username whose old handle no longer resolves; a typo in the username; a user who deleted their GitHub account.","solutions":["Confirm the username resolves to a real GitHub user account by opening https://github.com/<username>.","If the target is an organization, note that fetchTopLanguages does not support orgs via this endpoint; switch to a per-user account or a different data source.","Check for typos, casing, or a recently renamed handle, and update the request with the current login.","Handle USER_NOT_FOUND gracefully in your UI so the consumer sees 'user not found' rather than a raw stack trace."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Lightweight preflight: confirm the login resolves to a GitHub USER (not org)\nasync function assertGitHubUserExists(login, token) {\n  const resp = await axios.post(\n    \"https://api.github.com/graphql\",\n    { query: \"query($l:String!){user(login:$l){login}}\", variables: { l: login } },\n    { headers: { Authorization: `token ${token}` } },\n  );\n  if (resp.data.errors?.[0]?.type === \"NOT_FOUND\" || !resp.data.data?.user) {\n    throw new Error(`GitHub user '${login}' not found (or it is an organization)`);\n  }\n}\n// call before fetchTopLanguages to fail fast with a clearer message","typeGuard":"// Distinguish this error from others by its static type field\nfunction isUserNotFound(err) {\n  return (\n    err instanceof CustomError &&\n    err.type === CustomError.USER_NOT_FOUND\n  );\n}","tryCatchPattern":"try {\n  const topLangs = await fetchTopLanguages(username);\n} catch (err) {\n  if (err instanceof CustomError && err.type === CustomError.USER_NOT_FOUND) {\n    // render a 'user not found' card; do NOT retry — the login will not resolve\n    return res.send(renderError({ message: err.message, secondaryMessage: err.secondaryMessage }));\n  }\n  throw err;\n}","preventionTips":["Verify the login opens as https://github.com/<login> (a user profile, not an org page) before using it.","Remember fetchTopLanguages queries user(login:) and cannot resolve organizations.","Map USER_NOT_FOUND to a user-facing 'not found' state rather than retrying, since it is deterministic."],"tags":["github-api","graphql","user-not-found","validation"],"backgroundTag":null,"analyzedSha":"54a7985aeefda00d5eadb55b80c17c7f976c37d2","analyzedAt":"2026-08-12T23:20:41.776Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}