{"record":{"id":"c455fb609bc3a9f5","repo":"badges/shields","slug":"go-version-missing-in-go-mod","errorCode":null,"errorMessage":"Go version missing in go.mod","messagePattern":"Go version missing in go\\.mod","errorType":"exception","errorClass":"InvalidResponse","httpStatus":424,"severity":"error","filePath":"services/github/github-go-mod.service.js","lineNumber":72,"sourceCode":"        ],\n      },\n    },\n  }\n\n  static defaultBadgeData = { label: 'Go' }\n\n  static render({ version, branch }) {\n    return renderVersionBadge({\n      version,\n      tag: branch,\n      defaultLabel: 'Go',\n    })\n  }\n\n  static transform(content) {\n    const match = goVersionRegExp.exec(content)\n    if (!match) {\n      throw new InvalidResponse({\n        prettyMessage: 'Go version missing in go.mod',\n      })\n    }\n\n    return {\n      go: match[1],\n    }\n  }\n\n  async handle({ user, repo, branch }, { filename = 'go.mod' }) {\n    const content = await fetchRepoContent(this, {\n      user,\n      repo,\n      branch,\n      filename,\n    })\n    const { go } = this.constructor.transform(content)\n    return this.constructor.render({ version: go, branch })","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/services/github/github-go-mod.service.js#L54-L90","documentation":"The go-mod service parses go.mod content with goVersionRegExp and throws InvalidResponse 'Go version missing in go.mod' when the regex finds no `go` directive match. The file was fetched and decoded successfully, but it doesn't declare a Go toolchain version the service can extract. This indicates malformed or legacy go.mod content rather than a request problem.","triggerScenarios":"Requesting a go-mod badge where the repository's go.mod lacks a `go 1.x` directive entirely (pre-1.12-style go.mod or hand-written file), or the file content retrieved isn't actually a go.mod (wrong path).","commonSituations":"Very old modules created before the go directive became standard; files where the go directive was removed or commented out; fetching go.mod from a branch where it was replaced/emptied.","solutions":["Add a go directive to go.mod: run `go mod edit -go=1.21` (or appropriate version) and push.","Verify the service points at a branch where go.mod contains the go directive.","Ensure the requested file is actually the module's go.mod at the repo root (or correct subdirectory)."],"exampleFix":"// before (go.mod)\nmodule github.com/user/repo\n\nrequire (...) \n// after (go.mod)\nmodule github.com/user/repo\n\ngo 1.21\n\nrequire (...)","handlingStrategy":"validation","validationCode":"// check the go directive exists before requesting\nconst gomod = await fetch('https://raw.githubusercontent.com/OWNER/REPO/main/go.mod').then(r => r.text());\nif (!/^go \\d+/.m.test(gomod)) throw new Error('go.mod is missing a go directive');","typeGuard":"function hasGoDirective(gomodContent) {\n  return typeof gomodContent === 'string' && /^go\\s+\\d+(\\.\\d+)?/m.test(gomodContent);\n}","tryCatchPattern":"try {\n  const { go } = await getGoModVersion({ user, repo });\n} catch (e) {\n  if (e.prettyMessage === 'Go version missing in go.mod') {\n    // fall back to reading toolchain line or hide the badge\n  } else throw e;\n}","preventionTips":["Always declare a `go` directive in go.mod (`go mod edit -go=1.x`).","Run `go mod tidy` after upgrades so go.mod stays well-formed.","Point the badge at the branch where go.mod is valid."],"tags":["github","invalid-response","go","gomod","parsing"],"backgroundTag":"gomod-missing-go-version","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}