Skip to content
Latchkey

Go "go generate" Failures in CI - Fix Generator Errors

go generate runs the tools named in //go:generate directives. It fails when a generator binary is not installed on the runner, or when a CI freshness check finds the committed generated files no longer match their source.

What this error means

A go generate ./... step fails with executable file not found in $PATH for a generator (mockgen, stringer, protoc-gen-go), or a follow-up git diff step fails because regeneration changed committed files.

go output
app/store.go:3: running "mockgen": exec: "mockgen":
	executable file not found in $PATH
# or, the freshness check:
generated files are out of date; run 'go generate ./...'

Common causes

A generator tool not installed on the runner

The //go:generate directive invokes a binary (mockgen, stringer, protoc plugins) that is not on the CI runner’s PATH.

Generated files committed stale

Source changed but go generate was not re-run before committing, so a CI check that regenerates and diffs finds drift.

How to fix it

Install the generator tools

Install the exact tool versions the directives use before running generate.

Terminal
go install github.com/golang/mock/mockgen@v1.6.0
go install golang.org/x/tools/cmd/stringer@latest
go generate ./...

Pin tools in a tools.go file

Track generator dependencies in the module so versions are reproducible.

tools.go
//go:build tools
package tools

import (
	_ "github.com/golang/mock/mockgen"
	_ "golang.org/x/tools/cmd/stringer"
)

Enforce generated-file freshness in CI

.github/workflows/ci.yml
go generate ./...
git diff --exit-code

How to prevent it

  • Pin generator tools via a tools.go and install them in CI.
  • Re-run go generate ./... and commit before pushing.
  • Add a git diff --exit-code freshness check after generate.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →