badges/shields · error · InvalidResponse
invalid branch
Error message
invalid branch
What it means
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.
Source
Thrown at services/github/github-commit-activity.service.js:167
options: {
searchParams: {
sha: branch,
author: authorFilter,
per_page: '1',
since,
},
},
httpErrors: httpErrorsFor('repo or branch not found'),
})
}
static transform({ data }) {
const {
repository: { object: repo },
} = data
if (!repo) {
throw new InvalidResponse({ prettyMessage: 'invalid branch' })
}
return repo.history.totalCount
}
static transformAuthorFilter({ res }) {
const parsed = parseLinkHeader(res.headers.link)
if (!parsed) {
return 0
}
return parsed.last.page
}
static getIntervalQueryStartDate({ interval }) {
const now = new Date()
View on GitHub (pinned to 766fd8bc89)
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.
Example fix
// before []() // after []()
Defensive patterns
Strategy: validation
Validate before calling
// verify the branch exists before requesting
const heads = await fetch('https://api.github.com/repos/OWNER/REPO/branches?per_page=100').then(r => r.json());
if (!heads.some(b => b.name === branch)) throw new Error(`branch '${branch}' does not exist`); Type guard
function isCommitHistoryData(data) {
return data != null && data.repository != null && data.repository.object != null && typeof data.repository.object.totalCount === 'number';
} Try / catch
try {
const count = await getCommitActivity({ user, repo, branch });
} catch (e) {
if (e.prettyMessage === 'invalid branch') {
// fall back to default branch or surface a config error
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- undecodable content
- Go version missing in go.mod
- user/org not found
- invalid response data from auth endpoint
- unparseable svg response
AI-assisted analysis of badges/shields@766fd8bc89 (2026-08-30).
Data as JSON: /api/errors/e7024d16718a4c39.
Report an issue: GitHub.