anuraghazra/github-readme-stats · error · CustomError

USER_NOT_FOUND

USER_NOT_FOUND

Error message

Could not fetch user.

What it means

CustomError(USER_NOT_FOUND) thrown by fetchStats when the GraphQL stats response has an errors array whose first element has type === 'NOT_FOUND'. The message is res.data.errors[0].message if present, falling back to 'Could not fetch user.'. The secondary message ('Make sure the provided username is not an organization') reflects the most common cause: the stats query only inspects user(login:), so an organization login returns NOT_FOUND.

Source

Thrown at src/fetchers/stats.js:267

    totalDiscussionsStarted: 0,
    totalDiscussionsAnswered: 0,
    contributedTo: 0,
    rank: { level: "C", percentile: 100 },
  };

  let res = await statsFetcher({
    username,
    includeMergedPullRequests: include_merged_pull_requests,
    includeDiscussions: include_discussions,
    includeDiscussionsAnswers: include_discussions_answers,
    startTime: commits_year ? `${commits_year}-01-01T00:00:00Z` : undefined,
  });

  // Catch GraphQL errors.
  if (res.data.errors) {
    logger.error(res.data.errors);
    if (res.data.errors[0].type === "NOT_FOUND") {
      throw new CustomError(
        res.data.errors[0].message || "Could not fetch user.",
        CustomError.USER_NOT_FOUND,
      );
    }
    if (res.data.errors[0].message) {
      throw new CustomError(
        wrapTextMultiline(res.data.errors[0].message, 90, 1)[0],
        res.statusText,
      );
    }
    throw new CustomError(
      "Something went wrong while trying to retrieve the stats data using the GraphQL API.",
      CustomError.GRAPHQL_ERROR,
    );
  }

  const user = res.data.data.user;

View on GitHub (pinned to 54a7985aee)

Solutions

  1. Use a personal account login, not an organization (the stats card does not support orgs).
  2. Confirm the account exists at https://github.com/<username>.
  3. Fix typos and use the current login if renamed.

Example fix

// before
// GET /api/?username=microsoft  (organization -> USER_NOT_FOUND)

// after
// GET /api/?username=torvalds  (personal account)
Defensive patterns

Strategy: validation

Validate before calling

// Reject organizations up front — the stats query has no organization() branch.
async function assertIsUser(login, token) {
  const r = await fetch(`https://api.github.com/users/${login}`, {
    headers: { Authorization: `token ${token}` },
  });
  const j = await r.json();
  if (j.type === "Organization") {
    throw new Error(`${login} is an organization; the stats card only supports user accounts.`);
  }
}

Try / catch

try {
  return await fetchStats(username);
} catch (err) {
  if (err.type === CustomError.USER_NOT_FOUND) return null; // render a 'user not found' card
  throw err;
}

Prevention

When it happens

Trigger: The stats GraphQL query returns a NOT_FOUND error for the given login — typically because the login is an organization (the query has no organization(...) branch), the user does not exist, or the account was deleted/renamed.

Common situations: Passing an organization name to the stats endpoint (e.g. ?username=microsoft); a misspelled/deleted user; or a renamed account whose old login no longer resolves.

Related errors


AI-assisted analysis of anuraghazra/github-readme-stats@54a7985aee (2026-08-12). Data as JSON: /api/errors/bce2189446895f26. Report an issue: GitHub.