anuraghazra/github-readme-stats · error · Error
Unexpected behavior
Error message
Unexpected behavior
What it means
Defensive 'should never happen' Error at the end of fetchRepo. It is reached only if neither isUser (data.organization === null && data.user) nor isOrg (data.user === null && data.organization) is true, despite passing the earlier !data.user && !data.organization check. Concretely this requires data.user and data.organization to BOTH be non-null, or both non-null-but-falsy in an unexpected way — the GraphQL getRepo query is not expected to populate both.
Source
Thrown at src/fetchers/repo.js:114
...data.user.repository,
starCount: data.user.repository.stargazers.totalCount,
};
}
if (isOrg) {
if (
!data.organization.repository ||
data.organization.repository.isPrivate
) {
throw new Error("Organization Repository Not found");
}
return {
...data.organization.repository,
starCount: data.organization.repository.stargazers.totalCount,
};
}
throw new Error("Unexpected behavior");
};
export { fetchRepo };
export default fetchRepo;
View on GitHub (pinned to 54a7985aee)
Solutions
- Log the raw res.data to inspect the actual user/organization values GitHub returned.
- Check for any response-rewriting middleware, cache, or fetcher override in the deployment.
- Open an issue upstream — the GraphQL getRepo contract has changed.
Defensive patterns
Strategy: try-catch
Try / catch
// Defensive: log the unexpected shape and degrade gracefully rather than crash.
try {
return await fetchRepo(username, repo);
} catch (err) {
if (err.message === "Unexpected behavior") {
console.error("fetchRepo: both user and organization non-null for", username);
return null;
}
throw err;
} Prevention
- Treat this error as a bug report: capture the full res.data for the maintainer.
- Avoid response-rewriting proxies/caches in front of the GraphQL call that could synthesize a both-non-null shape.
When it happens
Trigger: A GitHub GraphQL API schema/behavior change that returns both user and organization non-null for the same login; or response mutation upstream (e.g. a custom fetcher/caching layer) that synthesizes a shape the code does not handle. Under normal GitHub behavior this branch is unreachable.
Common situations: Essentially never in production. If seen, it indicates either a GitHub API contract change or an interceptor (proxy/monkeypatch) altering the response shape. Treat as a bug report trigger rather than a user-fixable config issue.
Related errors
AI-assisted analysis of anuraghazra/github-readme-stats@54a7985aee (2026-08-12).
Data as JSON: /api/errors/16e178de8cf793df.
Report an issue: GitHub.