anuraghazra/github-readme-stats · error · CustomError
USER_NOT_FOUND
USER_NOT_FOUND
Error message
Could not fetch user.
What it means
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.
Source
Thrown at src/fetchers/top-languages.js:77
* @param {number} count_weight Weightage to be given to count.
* @returns {Promise<TopLangData>} Top languages data.
*/
const fetchTopLanguages = async (
username,
exclude_repo = [],
size_weight = 1,
count_weight = 0,
) => {
if (!username) {
throw new MissingParamError(["username"]);
}
const res = await retryer(fetcher, { login: username });
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 language data using the GraphQL API.",
CustomError.GRAPHQL_ERROR,
);
}
let repoNodes = res.data.data.user.repositories.nodes;
/** @type {Record<string, boolean>} */View on GitHub (pinned to 54a7985aee)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
// Lightweight preflight: confirm the login resolves to a GitHub USER (not org)
async function assertGitHubUserExists(login, token) {
const resp = await axios.post(
"https://api.github.com/graphql",
{ query: "query($l:String!){user(login:$l){login}}", variables: { l: login } },
{ headers: { Authorization: `token ${token}` } },
);
if (resp.data.errors?.[0]?.type === "NOT_FOUND" || !resp.data.data?.user) {
throw new Error(`GitHub user '${login}' not found (or it is an organization)`);
}
}
// call before fetchTopLanguages to fail fast with a clearer message Type guard
// Distinguish this error from others by its static type field
function isUserNotFound(err) {
return (
err instanceof CustomError &&
err.type === CustomError.USER_NOT_FOUND
);
} Try / catch
try {
const topLangs = await fetchTopLanguages(username);
} catch (err) {
if (err instanceof CustomError && err.type === CustomError.USER_NOT_FOUND) {
// render a 'user not found' card; do NOT retry — the login will not resolve
return res.send(renderError({ message: err.message, secondaryMessage: err.secondaryMessage }));
}
throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of anuraghazra/github-readme-stats@54a7985aee (2026-08-12).
Data as JSON: /api/errors/fa0797abd0a49739.
Report an issue: GitHub.