badges/shields · error · InvalidResponse
Go version missing in go.mod
Error message
Go version missing in go.mod
What it means
The GitLab go-mod service parses the repository's go.mod file and extracts the `go` directive via `goVersionRegExp`. If the regex matches nothing, `transform` throws `InvalidResponse` with 'Go version missing in go.mod'. The file was fetched, but it contains no usable Go version directive.
Source
Thrown at services/gitlab/gitlab-go-mod.service.js:113
const url = `${gitlabUrl}/api/v4/projects/${encodeURIComponent(
project,
)}/repository/files/${encodeURIComponent(filename)}/raw`
const options = { searchParams: { ref: branch || 'HEAD' } }
const httpErrors = httpErrorsFor('project or file not found')
const { buffer } = await this._request(
this.authHelper.withBearerAuthHeader({
url,
options,
httpErrors,
}),
)
return buffer
}
static transform(content) {
const match = goVersionRegExp.exec(content)
if (!match) {
throw new InvalidResponse({
prettyMessage: 'Go version missing in go.mod',
})
}
return {
go: match[1],
}
}
async handle(
{ user, repo, branch },
{ filename = 'go.mod', gitlabUrl = 'https://gitlab.com' },
) {
const content = await this.fetch({
user,
repo,
branch,
filename,View on GitHub (pinned to 766fd8bc89)
Solutions
- Add a `go 1.x` directive to go.mod and commit it
- Verify the badge URL's ref/branch points at a go.mod containing the directive
- Confirm the file path the service fetches is the real go.mod at repo root
Example fix
// before (go.mod) module example.com/m // after module example.com/m go 1.21
Defensive patterns
Strategy: validation
Validate before calling
const content = await fetch(rawGoModUrl).then(r => r.text())
if (!/^go\s+\d+\.\d+/m.test(content)) {
throw new Error('go.mod lacks a go directive; run: go mod edit -go=1.21')
} Type guard
null
Try / catch
try {
await fetchGoModBadge(project)
} catch (e) {
if (e.message === 'Go version missing in go.mod') return 'unknown'
throw e
} Prevention
- Keep a `go 1.x` directive in go.mod (`go mod edit -go=1.21`)
- Ensure the badge URL targets the branch/ref where go.mod has the directive
- Verify the fetched file is actually go.mod at the module root
When it happens
Trigger: go.mod exists but lacks a `go X.Y` directive (old modules created before Go 1.12 convention, or hand-stripped files); the fetched content is not actually a go.mod (wrong path/ref, or GitLab returned an error page).
Common situations: Legacy module predating the go directive; someone edited go.mod and removed the directive; badge URL points at a branch/ref where go.mod differs; GitLab raw endpoint returning non-go.mod content due to wrong file path.
Related errors
- Version missing in ${filename}
- Field `message` is required
- invalid config.yml
- Go version missing in go.mod
- no commits found
AI-assisted analysis of badges/shields@766fd8bc89 (2026-08-30).
Data as JSON: /api/errors/003d0d4c2c1edfa5.
Report an issue: GitHub.