{"record":{"id":"95d5b1a56ff875eb","repo":"anuraghazra/github-readme-stats","slug":"invalid-username-provided","errorCode":null,"errorMessage":"Invalid username provided.","messagePattern":"Invalid username provided\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/fetchers/stats.js","lineNumber":194,"sourceCode":"      Accept: \"application/vnd.github.cloak-preview\",\n      Authorization: `token ${token}`,\n    },\n  });\n};\n\n/**\n * Fetch all the commits for all the repositories of a given username.\n *\n * @param {string} username GitHub username.\n * @returns {Promise<number>} Total commits.\n *\n * @description Done like this because the GitHub API does not provide a way to fetch all the commits. See\n * #92#issuecomment-661026467 and #211 for more information.\n */\nconst totalCommitsFetcher = async (username) => {\n  if (!githubUsernameRegex.test(username)) {\n    logger.log(\"Invalid username provided.\");\n    throw new Error(\"Invalid username provided.\");\n  }\n\n  let res;\n  try {\n    res = await retryer(fetchTotalCommits, { login: username });\n  } catch (err) {\n    logger.log(err);\n    throw new Error(err);\n  }\n\n  const totalCount = res.data.total_count;\n  if (!totalCount || isNaN(totalCount)) {\n    throw new CustomError(\n      \"Could not fetch total commits.\",\n      CustomError.GITHUB_REST_API_ERROR,\n    );\n  }\n  return totalCount;","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/anuraghazra/github-readme-stats/blob/54a7985aeefda00d5eadb55b80c17c7f976c37d2/src/fetchers/stats.js#L176-L212","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n// GET /api/?username=john.doe&include_all_commits=true  (dots invalid)\n\n// after\n// GET /api/?username=johndoe&include_all_commits=true\n// or drop the flag:\n// GET /api/?username=john.doe  (uses GraphQL contributions instead)","handlingStrategy":"validation","validationCode":"// Mirror the same regex fetchStats+totalCommitsFetcher use.\nimport githubUsernameRegex from \"github-username-regex\";\nfunction assertValidUsernameForAllCommits(username) {\n  if (!githubUsernameRegex.test(username)) {\n    throw new Error(\n      `\"${username}\" is not a valid GitHub login for include_all_commits (alphanumeric/hyphens, <=39 chars).`,\n    );\n  }\n}","typeGuard":"import githubUsernameRegex from \"github-username-regex\";\nconst isValidGithubUsername = (u) => typeof u === \"string\" && githubUsernameRegex.test(u);","tryCatchPattern":null,"preventionTips":["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."],"tags":["stats","validation","username","rest-api","include-all-commits"],"backgroundTag":null,"analyzedSha":"54a7985aeefda00d5eadb55b80c17c7f976c37d2","analyzedAt":"2026-08-12T23:20:41.776Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}