anuraghazra/github-readme-stats · error · CustomError
GITHUB_REST_API_ERROR
GITHUB_REST_API_ERROR
Error message
Could not fetch total commits.
What it means
CustomError(GITHUB_REST_API_ERROR) thrown by totalCommitsFetcher when the REST /search/commits response has no usable total_count (!totalCount || isNaN(totalCount)). The retryer returned a response object, but res.data.total_count is missing, 0, or non-numeric. The secondary message is 'Please try again later' (TRY_AGAIN_LATER), framing it as a transient GitHub REST API issue.
Source
Thrown at src/fetchers/stats.js:207
* #92#issuecomment-661026467 and #211 for more information.
*/
const totalCommitsFetcher = async (username) => {
if (!githubUsernameRegex.test(username)) {
logger.log("Invalid username provided.");
throw new Error("Invalid username provided.");
}
let res;
try {
res = await retryer(fetchTotalCommits, { login: username });
} catch (err) {
logger.log(err);
throw new Error(err);
}
const totalCount = res.data.total_count;
if (!totalCount || isNaN(totalCount)) {
throw new CustomError(
"Could not fetch total commits.",
CustomError.GITHUB_REST_API_ERROR,
);
}
return totalCount;
};
/**
* Fetch stats for a given username.
*
* @param {string} username GitHub username.
* @param {boolean} include_all_commits Include all commits.
* @param {string[]} exclude_repo Repositories to exclude.
* @param {boolean} include_merged_pull_requests Include merged pull requests.
* @param {boolean} include_discussions Include discussions.
* @param {boolean} include_discussions_answers Include discussions answers.
* @param {number|undefined} commits_year Year to count total commits
* @returns {Promise<import("./types").StatsData>} Stats data.View on GitHub (pinned to 54a7985aee)
Solutions
- Retry after a short delay — the secondary message says 'try again later' and most causes are transient.
- Verify GitHub REST API status at https://www.githubstatus.com.
- If the user genuinely has 0 commits, consider whether the !totalCount guard (which treats 0 as failure) is appropriate; report upstream if so.
- Fall back to include_all_commits=false to use GraphQL contributions instead.
Example fix
// before // GET /api/?username=X&include_all_commits=true -> 'Could not fetch total commits.' // after (fall back to GraphQL contributions count) // GET /api/?username=X
Defensive patterns
Strategy: fallback
Try / catch
// Fall back to the GraphQL contributions count when the REST total-count path fails.
try {
stats.totalCommits = await totalCommitsFetcher(username);
} catch (err) {
if (err.type === CustomError.GITHUB_REST_API_ERROR) {
// degrade to GraphQL-sourced contributions instead of failing the whole card
stats.totalCommits = user.commits.totalCommitContributions;
} else throw err;
} Prevention
- Treat GITHUB_REST_API_ERROR as transient — retry once before falling back.
- If you don't strictly need all-time commits, leave include_all_commits=false to avoid this path.
When it happens
Trigger: GitHub's /search/commits endpoint returns a payload without total_count (e.g. an error envelope, an empty 200, or a non-JSON body parsed to something unexpected); total_count is literally 0; or the field is present but non-numeric. Because the prior try/catch already handled thrown errors, this is specifically a 'responded but unusable' case.
Common situations: GitHub REST API incident/degraded state returning an unusual body; the cloak-preview Accept header no longer being honored after an API change; or a username that legitimately has zero matching commits (total_count === 0 trips the !totalCount guard).
Related errors
AI-assisted analysis of anuraghazra/github-readme-stats@54a7985aee (2026-08-12).
Data as JSON: /api/errors/05f6e0813bf8ed4b.
Report an issue: GitHub.