{"record":{"id":"e7024d16718a4c39","repo":"badges/shields","slug":"invalid-branch","errorCode":null,"errorMessage":"invalid branch","messagePattern":"invalid branch","errorType":"exception","errorClass":"InvalidResponse","httpStatus":424,"severity":"error","filePath":"services/github/github-commit-activity.service.js","lineNumber":167,"sourceCode":"      options: {\n        searchParams: {\n          sha: branch,\n          author: authorFilter,\n          per_page: '1',\n          since,\n        },\n      },\n      httpErrors: httpErrorsFor('repo or branch not found'),\n    })\n  }\n\n  static transform({ data }) {\n    const {\n      repository: { object: repo },\n    } = data\n\n    if (!repo) {\n      throw new InvalidResponse({ prettyMessage: 'invalid branch' })\n    }\n\n    return repo.history.totalCount\n  }\n\n  static transformAuthorFilter({ res }) {\n    const parsed = parseLinkHeader(res.headers.link)\n\n    if (!parsed) {\n      return 0\n    }\n\n    return parsed.last.page\n  }\n\n  static getIntervalQueryStartDate({ interval }) {\n    const now = new Date()\n","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/services/github/github-commit-activity.service.js#L149-L185","documentation":"The GitHub commit-activity service calls transform() on the GraphQL commit history response and throws InvalidResponse with message 'invalid branch' when the repository object is missing. This means GitHub returned a response without the expected `repository.object` structure, typically because the requested branch does not exist. It signals bad user input (unknown branch) surfaced as an invalid-response error rather than a network failure.","triggerScenarios":"Calling the commit-activity badge/endpoint for a user/repo where the `branch` query parameter names a branch that does not exist in the repository, so the GraphQL query for that ref's history returns null and destructuring yields no `repo` object.","commonSituations":"Default branch renamed or deleted (e.g. master -> main) while badges still point at the old branch; typos in the branch param in a README badge URL; private/renamed repos where the ref resolution fails.","solutions":["Verify the branch name in the badge/URL matches an existing branch (git ls-remote --heads <repo>).","Update stale badge URLs after renaming the default branch (master to main).","Omit the branch parameter to use the repository's default branch instead of hardcoding one."],"exampleFix":"// before\n[![commit activity](https://img.shields.io/github/commit-activity/m/user/repo?branch=master)]()\n// after\n[![commit activity](https://img.shields.io/github/commit-activity/m/user/repo?branch=main)]()","handlingStrategy":"validation","validationCode":"// verify the branch exists before requesting\nconst heads = await fetch('https://api.github.com/repos/OWNER/REPO/branches?per_page=100').then(r => r.json());\nif (!heads.some(b => b.name === branch)) throw new Error(`branch '${branch}' does not exist`);","typeGuard":"function isCommitHistoryData(data) {\n  return data != null && data.repository != null && data.repository.object != null && typeof data.repository.object.totalCount === 'number';\n}","tryCatchPattern":"try {\n  const count = await getCommitActivity({ user, repo, branch });\n} catch (e) {\n  if (e.prettyMessage === 'invalid branch') {\n    // fall back to default branch or surface a config error\n  } else throw e;\n}","preventionTips":["Never hardcode branch names in badges; omit the branch param to use the default branch.","Update badge URLs whenever renaming the default branch.","Add a CI check that validates badge URLs against the repo's live branches."],"tags":["github","invalid-response","branch-not-found","graphql"],"backgroundTag":"branch-not-found","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}