{"record":{"id":"ae18b57b7b7c6a90","repo":"golang/go","slug":"could-not-locate-sumdb-file-missing-gopath-s","errorCode":null,"errorMessage":"could not locate sumdb file: missing $GOPATH: %s","messagePattern":"could not locate sumdb file: missing \\$GOPATH: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modfetch/sumdb.go","lineNumber":237,"sourceCode":"\t})\n\tif errors.Is(err, fs.ErrNotExist) {\n\t\t// No proxies, or all proxies failed (with 404, 410, or were allowed\n\t\t// to fall back), or we reached an explicit \"direct\" or \"off\".\n\t\tc.base = c.direct\n\t} else if err != nil {\n\t\tc.baseErr = err\n\t}\n}\n\n// ReadConfig reads the key from c.key\n// and otherwise reads the config (a latest tree head) from GOPATH/pkg/sumdb/<file>.\nfunc (c *dbClient) ReadConfig(file string) (data []byte, err error) {\n\tif file == \"key\" {\n\t\treturn []byte(c.key), nil\n\t}\n\n\tif cfg.SumdbDir == \"\" {\n\t\treturn nil, fmt.Errorf(\"could not locate sumdb file: missing $GOPATH: %s\",\n\t\t\tcfg.GoPathError)\n\t}\n\ttarg := filepath.Join(cfg.SumdbDir, file)\n\tdata, err = lockedfile.Read(targ)\n\tif errors.Is(err, fs.ErrNotExist) {\n\t\t// Treat non-existent as empty, to bootstrap the \"latest\" file\n\t\t// the first time we connect to a given database.\n\t\treturn []byte{}, nil\n\t}\n\treturn data, err\n}\n\n// WriteConfig rewrites the latest tree head.\nfunc (*dbClient) WriteConfig(file string, old, new []byte) error {\n\tif file == \"key\" {\n\t\t// Should not happen.\n\t\treturn fmt.Errorf(\"cannot write key\")\n\t}","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modfetch/sumdb.go#L219-L255","documentation":"This error is thrown by dbClient.ReadConfig when it needs to read a sumdb state file from disk (the 'latest' tree head cached under GOPATH/pkg/sumdb/) but cfg.SumdbDir is empty. cfg.SumdbDir is derived from GOPATH; if GOPATH cannot be determined (cfg.GoPathError is set), SumdbDir stays empty and this error fires with the underlying GOPATH error.","triggerScenarios":"The sumdb client needs to read its cached configuration (latest transparency-log tree head) from cfg.SumdbDir but GOPATH is unset or invalid. This happens during module operations that contact the checksum database (go mod download, go get, go mod verify) when GOPATH is not properly configured.","commonSituations":"GOPATH is not set and cannot be inferred (no default ~/go directory is usable). A CI environment or container that doesn't set GOPATH or HOME. A restricted filesystem where the GOPATH directory can't be created. GOENV or HOME environment variables point to unwritable locations.","solutions":["Set GOPATH explicitly: 'go env -w GOPATH=/path/to/gopath' or 'export GOPATH=/path/to/gopath'.","Ensure HOME is set: Go derives a default GOPATH from HOME/go if GOPATH is unset. Check with 'echo $HOME'.","Run 'go env GOPATH' to see the effective value and the error if it can't be determined.","In Docker containers, set HOME or GOPATH: 'ENV GOPATH=/go' or 'ENV HOME=/root'."],"exampleFix":"# before: GOPATH unset in container\n$ docker run --rm golang:alpine go mod download\n# could not locate sumdb file: missing $GOPATH: ...\n\n# after: set GOPATH\n$ docker run --rm -e GOPATH=/go golang:alpine go mod download\n# or use the default which requires HOME\n$ docker run --rm -e HOME=/root golang:alpine go mod download","handlingStrategy":"validation","validationCode":"// Check GOPATH is set before running go mod commands\nfunc validateGOPATH() error {\n    out, err := exec.Command(\"go\", \"env\", \"GOPATH\").Output()\n    if err != nil { return err }\n    val := strings.TrimSpace(string(out))\n    if val == \"\" {\n        return fmt.Errorf(\"GOPATH is empty; run: go env -w GOPATH=/path/to/go\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if strings.Contains(stderr, \"could not locate sumdb file\") && strings.Contains(stderr, \"GOPATH\") {\n    // GOPATH not set; set it\n    // exec.Command(\"go\", \"env\", \"-w\", \"GOPATH=/tmp/go\")\n}","preventionTips":["Always set GOPATH (or HOME) in CI and containers","Use 'go env GOPATH' to verify before running module operations","Ensure the GOPATH directory is writable","Set GOPATH in Dockerfiles: ENV GOPATH=/go"],"tags":["go-sumdb","gopath","configuration","env-var","filesystem"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}