{"record":{"id":"53b76b9b31cec75c","repo":"JuliusBrussee/caveman","slug":"go-build-failed-for-artifact","errorCode":null,"errorMessage":"go build failed for ${artifact}","messagePattern":"go build failed for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/build-release-binaries.mjs","lineNumber":71,"sourceCode":"  }\n  return { out, targets: targets.length ? targets : RELEASE_TARGETS, list: false };\n}\n\nfunction build({ out, targets }) {\n  mkdirSync(out, { recursive: true });\n  const artifacts = [];\n  for (const [goos, arch] of targets) {\n    for (const [name, packagePath] of RELEASE_BINARIES) {\n      const artifact = releaseArtifactName(name, goos, arch);\n      const output = join(out, artifact);\n      process.stderr.write(`build ${artifact}\\n`);\n      const result = spawnSync(\"go\", [\"build\", \"-trimpath\", \"-o\", output, packagePath], {\n        cwd: root,\n        env: { ...process.env, CGO_ENABLED: \"0\", GOOS: goos, GOARCH: arch },\n        stdio: \"inherit\",\n      });\n      if (result.error) throw result.error;\n      if (result.status !== 0) throw new Error(`go build failed for ${artifact}`);\n      artifacts.push(artifact);\n    }\n  }\n  artifacts.sort();\n  const checksums = artifacts.map((artifact) => {\n    const digest = createHash(\"sha256\").update(readFileSync(join(out, artifact))).digest(\"hex\");\n    return `${digest}  ${artifact}`;\n  }).join(\"\\n\") + \"\\n\";\n  writeFileSync(join(out, \"checksums.txt\"), checksums, { mode: 0o600 });\n  return artifacts;\n}\n\nif (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {\n  try {\n    const options = parseArgs(process.argv.slice(2));\n    if (options.list) process.stdout.write(`${releaseArtifactNames(options.targets).sort().join(\"\\n\")}\\n`);\n    else process.stdout.write(`built ${build(options).length} signed-release inputs in ${options.out}\\n`);\n  } catch (error) {","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/scripts/build-release-binaries.mjs#L53-L89","documentation":"Thrown by the release-binary build script when a `go build` invocation for a release artifact exits with a non-zero status (the child's own compiler output has already been printed to stderr via stdio: \"inherit\"). The wrapper adds the artifact name because the Go toolchain error alone does not say which GOOS/GOARCH cross-compile target failed.","triggerScenarios":"Running the release script where the Go toolchain fails for a specific target: compile errors in the package being built, unsupported GOOS/GOARCH combination for a dependency (e.g. a package using cgo or syscall APIs unavailable on that platform), missing Go toolchain, or a full/corrupt module cache. Note CGO_ENABLED=0 is forced in the env.","commonSituations":"Adding a dependency that does not cross-compile to windows/arm64 or plan9 etc.; stale go.sum after a dependency bump; Go not installed or an ancient Go version rejecting the go directive in go.mod; building from a clean CI container without a warmed module cache while GOPROXY is misconfigured.","solutions":["Read the go compiler output printed just above the error — it names the actual file/package and cause; fix that first.","Reproduce manually with the same env: GOOS=<goos> GOARCH=<arch> CGO_ENABLED=0 go build -trimpath -o /tmp/test <packagePath> to iterate faster.","If a dependency does not support the target, either drop that target via --target or replace/guard the dependency with build tags.","Ensure a current Go toolchain is installed and `go mod download` succeeds (clean module cache with `go clean -modcache` if it is corrupt)."],"exampleFix":"# before: dep uses cgo-only APIs\nGOOS=windows GOARCH=arm64 go build ./... # fails -> script throws \"go build failed for mytool-windows-arm64.exe\"\n\n# after: guard the dep with build tags\n//go:build !windows\nimport \"github.com/some/cgo-only-lib\"","handlingStrategy":"try-catch","validationCode":"import { spawnSync } from \"node:child_process\";\nconst probe = spawnSync(\"go\", [\"version\"], { stdio: \"pipe\" });\nif (probe.status !== 0) throw new Error(\"Go toolchain unavailable — install Go first\");","typeGuard":null,"tryCatchPattern":"try {\n  buildRelease({ targets: [[\"linux\", \"amd64\"]] });\n} catch (err) {\n  if (/^go build failed for /.test(err.message)) {\n    // artifact name in the message maps to GOOS/GOARCH; the real compiler\n    // error was already streamed to stderr — surface it, do not retry blindly\n    process.exitCode = 1;\n  } else throw err;\n}","preventionTips":["Cross-compile each target locally (GOOS/GOARCH CGO_ENABLED=0 go build) before cutting a release.","Pin the Go version in CI to the version go.mod requires.","Run `go mod tidy && go test ./...` before invoking the release script."],"tags":["build","golang","cross-compile","release","toolchain"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}