anuraghazra/github-readme-stats · error · Error
Invalid username provided.
Error message
Invalid username provided.
What it means
Generic Error thrown by totalCommitsFetcher when the username fails the github-username-regex test, before any network call. This fetcher is only invoked when include_all_commits=true (it backs the REST commits-search path), so the regex gate guards the secondary /search/commits REST endpoint specifically. The same username already passed fetchStats, so reaching here means the value is non-empty but violates GitHub's username rules (alphanumeric + hyphens, no leading/trailing/consecutive hyphens, max 39 chars).
Source
Thrown at src/fetchers/stats.js:194
Accept: "application/vnd.github.cloak-preview",
Authorization: `token ${token}`,
},
});
};
/**
* Fetch all the commits for all the repositories of a given username.
*
* @param {string} username GitHub username.
* @returns {Promise<number>} Total commits.
*
* @description Done like this because the GitHub API does not provide a way to fetch all the commits. See
* #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;View on GitHub (pinned to 54a7985aee)
Solutions
- Use a valid GitHub login (alphanumeric and hyphens only, 1-39 chars, no leading/trailing/double hyphens).
- If you don't actually need all-time commits, drop include_all_commits=true to use the GraphQL contributions count instead (which does not run this regex check).
- Strip whitespace and re-test against github-username-regex before issuing the request.
Example fix
// before // GET /api/?username=john.doe&include_all_commits=true (dots invalid) // after // GET /api/?username=johndoe&include_all_commits=true // or drop the flag: // GET /api/?username=john.doe (uses GraphQL contributions instead)
Defensive patterns
Strategy: validation
Validate before calling
// Mirror the same regex fetchStats+totalCommitsFetcher use.
import githubUsernameRegex from "github-username-regex";
function assertValidUsernameForAllCommits(username) {
if (!githubUsernameRegex.test(username)) {
throw new Error(
`"${username}" is not a valid GitHub login for include_all_commits (alphanumeric/hyphens, <=39 chars).`,
);
}
} Type guard
import githubUsernameRegex from "github-username-regex"; const isValidGithubUsername = (u) => typeof u === "string" && githubUsernameRegex.test(u);
Prevention
- Validate the username against github-username-regex whenever include_all_commits=true.
- Remember dots are NOT allowed in GitHub logins — filter them out before the call.
When it happens
Trigger: A request with include_all_commits=true whose username contains illegal characters, starts/ends with a hyphen, has consecutive hyphens, or exceeds 39 characters. The logger logs 'Invalid username provided.' and the Error propagates.
Common situations: Username containing dots (not allowed by GitHub but accepted by some other systems), an email address mistakenly passed as username, a handle with whitespace/symbols, or a >39 char value.
Related errors
- ${err}
- GITHUB_REST_API_ERROR
- Missing params "username" make sure you pass the parameters
- Could not render stats card.
- Missing params "id" make sure you pass the parameters in URL
AI-assisted analysis of anuraghazra/github-readme-stats@54a7985aee (2026-08-12).
Data as JSON: /api/errors/95d5b1a56ff875eb.
Report an issue: GitHub.