{"record":{"id":"272aa4b04cf42ba8","repo":"golang/go","slug":"built-pkgsite-binary-does-not-exist-w","errorCode":null,"errorMessage":"built pkgsite binary does not exist: %w","messagePattern":"built pkgsite binary does not exist: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/doc/pkgsite.go","lineNumber":148,"sourceCode":"\tfields := strings.Fields(vars)\n\tif err == nil && len(fields) == 2 {\n\t\tgoproxy, gomodcache := fields[0], fields[1]\n\t\tgomodcache = filepath.Join(gomodcache, \"cache\", \"download\")\n\t\t// Convert absolute path to file URL. pkgsite will not accept\n\t\t// Windows absolute paths because they look like a host:path remote.\n\t\t// TODO(golang.org/issue/32456): use url.FromFilePath when implemented.\n\t\tif strings.HasPrefix(gomodcache, \"/\") {\n\t\t\tgomodcache = \"file://\" + gomodcache\n\t\t} else {\n\t\t\tgomodcache = \"file:///\" + filepath.ToSlash(gomodcache)\n\t\t}\n\t\tenv = append(env, \"GOPROXY=\"+gomodcache+\",\"+goproxy)\n\t}\n\n\tpkgsite := buildPkgsite(ctx)\n\tif os.Getenv(\"TEST_GODOC_BUILD_ONLY\") != \"\" {\n\t\tif _, err := os.Stat(pkgsite); err != nil {\n\t\t\treturn fmt.Errorf(\"built pkgsite binary does not exist: %w\", err)\n\t\t}\n\t\treturn nil\n\t}\n\tcmd := exec.Command(pkgsite, \"-gorepo\", cfg.GOROOT, \"-http\", addr, \"-open\", path)\n\tcmd.Env = env\n\tcmd.Stdout = os.Stderr\n\tcmd.Stderr = os.Stderr\n\n\tif err := cmd.Run(); err != nil {\n\t\tif ee, ok := errors.AsType[*exec.ExitError](err); ok {\n\t\t\t// Exit with the same exit status as pkgsite to avoid\n\t\t\t// printing of \"exit status\" error messages.\n\t\t\t// Any relevant messages have already been printed\n\t\t\t// to stdout or stderr.\n\t\t\tos.Exit(ee.ExitCode())\n\t\t}\n\t\treturn err\n\t}","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/doc/pkgsite.go#L130-L166","documentation":"Thrown only on the test path of doPkgsite (when TEST_GODOC_BUILD_ONLY is set): after buildPkgsite(ctx) runs, os.Stat(pkgsite) is checked and the error wraps the failing stat. It signals that the pkgsite helper binary was not produced where the build claimed it would be. End users of `go doc` never see it; it exists so the test harness can fail fast when the bundled pkgsite build is broken.","triggerScenarios":"Running the cmd/go godoc test with TEST_GODOC_BUILD_ONLY=1 in the environment and buildPkgsite returning a path whose file does not yet exist on disk (build was skipped, failed silently, or wrote elsewhere).","commonSituations":"A broken/short-circuited buildPkgsite in a dev toolchain; cross-compile setups where the built binary lands in a different GOBIN/GOPATH/bin; stale test shims that mock the build without writing the file; partial builds interrupted before the pkgsite target completes.","solutions":["Inspect the underlying wrapped error (%w) from os.Stat — it tells you whether the path is missing, a permission issue, or a stale symlink.","Confirm buildPkgsite actually wrote the binary to the returned path; run the build step standalone and `ls -l` the result.","Re-run `go build`/`go install` for the pkgsite target with the same GOOS/GOARCH the test uses, so the output path matches.","If you are mocking buildPkgsite in a test, make the stub write an empty file at the returned path before returning."],"exampleFix":"// before (test stub that returns a path but never writes it)\nfunc buildPkgsite(ctx context.Context) string { return \"/tmp/pkgsite\" }\n// after\nfunc buildPkgsite(ctx context.Context) string {\n    p := filepath.Join(os.TempDir(), \"pkgsite\")\n    if _, err := os.Stat(p); err != nil {\n        if err := os.WriteFile(p, []byte(\"#!/bin/sh\\n\"), 0755); err != nil { panic(err) }\n    }\n    return p\n}","handlingStrategy":"validation","validationCode":"// Before relying on the pkgsite path returned by buildPkgsite,\n// verify it actually exists on disk.\nif _, err := os.Stat(pkgsitePath); err != nil {\n    return fmt.Errorf(\"pkgsite not built yet: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat TEST_GODOC_BUILD_ONLY as a build smoke-test — never assert on the binary's contents.","Make any test stub of buildPkgsite write the file at the returned path before returning.","When changing build output locations, update both the builder and the consumer."],"tags":["testing","build","pkgsite","go-command"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}