{"id":"eba90a67ef3c9bc1","repo":"gohugoio/hugo","slug":"failed-to-execute-go-v-s-t","errorCode":null,"errorMessage":"failed to execute 'go %v': %s %T","messagePattern":"failed to execute 'go (.+?)': (.+?) %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/client.go","lineNumber":811,"sourceCode":"\t\t\tc.goBinaryStatus = goBinaryStatusNotFound\n\t\t\treturn nil\n\t\t}\n\n\t\tif strings.Contains(stderr.String(), \"invalid version: unknown revision\") {\n\t\t\t// See https://github.com/gohugoio/hugo/issues/6825\n\t\t\tc.logger.Println(`An unknown revision most likely means that someone has deleted the remote ref (e.g. with a force push to GitHub).\nTo resolve this, you need to manually edit your go.mod file and replace the version for the module in question with a valid ref.\n\nThe easiest is to just enter a valid branch name there, e.g. master, which would be what you put in place of 'v0.5.1' in the example below.\n\nrequire github.com/gohugoio/hugo-mod-jslibs/instantpage v0.5.1\n\nIf you then run 'hugo mod graph' it should resolve itself to the most recent version (or commit if no semver versions are available).`)\n\t\t}\n\n\t\t_, ok := err.(*exec.ExitError)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"failed to execute 'go %v': %s %T\", args, err, err)\n\t\t}\n\n\t\t// Too old Go version\n\t\tif strings.Contains(stderr.String(), \"flag provided but not defined\") {\n\t\t\tc.goBinaryStatus = goBinaryStatusTooOld\n\t\t\treturn nil\n\t\t}\n\n\t\treturn fmt.Errorf(\"go command failed: %s\", stderr)\n\n\t}\n\n\treturn nil\n}\n\nvar goOutputReplacer = strings.NewReplacer(\n\t\"go: to add module requirements and sums:\", \"hugo: to add module requirements and sums:\",\n\t\"go mod tidy\", \"hugo mod tidy\",","sourceCodeStart":793,"sourceCodeEnd":829,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/modules/client.go#L793-L829","documentation":"Hugo's module Client wraps the Go toolchain (`go get`, `go mod download`, etc.) to manage Hugo Modules. In `runGo` (modules/client.go:811), if `cmd.Run()` fails with an error that is NOT an `*exec.ExitError` (i.e. the process could not even be started or was killed abnormally, rather than exiting with a non-zero status), Hugo reports this error including the args, the error text, and its Go type. Notably, `exec.ErrNotFound` (go binary missing) is handled separately and silently tolerated, so this path means something more unusual prevented execution.","triggerScenarios":"Any `hugo mod` command (get, tidy, graph, vendor, verify) or a build that resolves Hugo Modules, when the `go` process fails to launch or dies without a normal exit status: permission denied on the go binary, context cancellation/timeout via `hexec.WithContext`, an invalid working directory passed via `WithDir`, or the process being killed by the OS (OOM, signal).","commonSituations":"A `go` on PATH that is not executable or is a broken shim/symlink; CI containers with a corrupt Go install; security policies (hexec allowlist) blocking execution; Hugo's working directory deleted mid-build; the process killed by an OOM killer in constrained CI runners.","solutions":["Run `go version` in the same shell/environment Hugo uses to confirm the binary starts at all.","Check the %T type printed in the message — a context error means a timeout/cancellation; *fs.PathError or permission errors point at the binary or working dir.","Verify the go binary permissions and that it matches the host architecture (e.g. amd64 binary on arm64).","Check hexec security config (`security.exec.allow`) permits `go`.","Reinstall Go or fix PATH if the binary is a broken symlink."],"exampleFix":"# before: broken symlink\nls -l $(which go)  # -> dangling link\n# after: reinstall and verify\nsudo rm /usr/local/bin/go\nexport PATH=/usr/local/go/bin:$PATH\ngo version && hugo mod tidy","handlingStrategy":"validation","validationCode":"if _, err := exec.LookPath(\"go\"); err != nil {\n    return fmt.Errorf(\"go binary not found in PATH; Hugo Modules require Go: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := client.Get(args...); err != nil {\n    if strings.Contains(err.Error(), \"failed to execute\") {\n        // go toolchain missing or broken environment\n    }\n    return err\n}","preventionTips":["Verify the go binary is installed and on PATH before invoking any module operation","Pin a minimum Go version in CI images and check it at startup","Ensure GOPATH/GOMODCACHE directories are writable in sandboxed environments","Log the resolved go executable path at startup for debuggability"],"tags":["go-toolchain","hugo-modules","exec","environment"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}