badges/shields · error · InvalidResponse

Go version missing in go.mod

Error message

Go version missing in go.mod

What it means

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.

Source

Thrown at services/github/github-go-mod.service.js:72

        ],
      },
    },
  }

  static defaultBadgeData = { label: 'Go' }

  static render({ version, branch }) {
    return renderVersionBadge({
      version,
      tag: branch,
      defaultLabel: 'Go',
    })
  }

  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' }) {
    const content = await fetchRepoContent(this, {
      user,
      repo,
      branch,
      filename,
    })
    const { go } = this.constructor.transform(content)
    return this.constructor.render({ version: go, branch })

View on GitHub (pinned to 766fd8bc89)

Solutions

  1. Add a go directive to go.mod: run `go mod edit -go=1.21` (or appropriate version) and push.
  2. Verify the service points at a branch where go.mod contains the go directive.
  3. Ensure the requested file is actually the module's go.mod at the repo root (or correct subdirectory).

Example fix

// before (go.mod)
module github.com/user/repo

require (...) 
// after (go.mod)
module github.com/user/repo

go 1.21

require (...)
Defensive patterns

Strategy: validation

Validate before calling

// check the go directive exists before requesting
const gomod = await fetch('https://raw.githubusercontent.com/OWNER/REPO/main/go.mod').then(r => r.text());
if (!/^go \d+/.m.test(gomod)) throw new Error('go.mod is missing a go directive');

Type guard

function hasGoDirective(gomodContent) {
  return typeof gomodContent === 'string' && /^go\s+\d+(\.\d+)?/m.test(gomodContent);
}

Try / catch

try {
  const { go } = await getGoModVersion({ user, repo });
} catch (e) {
  if (e.prettyMessage === 'Go version missing in go.mod') {
    // fall back to reading toolchain line or hide the badge
  } else throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of badges/shields@766fd8bc89 (2026-08-30). Data as JSON: /api/errors/c455fb609bc3a9f5. Report an issue: GitHub.