{"record":{"id":"759798c50697d1c6","repo":"golang/go","slug":"invalid-gosumdb-too-many-fields","errorCode":null,"errorMessage":"invalid GOSUMDB: too many fields","messagePattern":"invalid GOSUMDB: too many fields","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modfetch/sumdb.go","lineNumber":117,"sourceCode":"\tif gosumdb == \"sum.golang.google.cn\" {\n\t\tgosumdb = \"sum.golang.org https://sum.golang.google.cn\"\n\t}\n\n\tif gosumdb == \"off\" {\n\t\treturn \"\", nil, fmt.Errorf(\"checksum database disabled by GOSUMDB=off\")\n\t}\n\n\tkey := strings.Fields(gosumdb)\n\tif len(key) >= 1 {\n\t\tif k := knownGOSUMDB[key[0]]; k != \"\" {\n\t\t\tkey[0] = k\n\t\t}\n\t}\n\tif len(key) == 0 {\n\t\treturn \"\", nil, fmt.Errorf(\"missing GOSUMDB\")\n\t}\n\tif len(key) > 2 {\n\t\treturn \"\", nil, fmt.Errorf(\"invalid GOSUMDB: too many fields\")\n\t}\n\tvkey, err := note.NewVerifier(key[0])\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"invalid GOSUMDB: %v\", err)\n\t}\n\tname := vkey.Name()\n\n\t// No funny business in the database name.\n\tdirect, err := url.Parse(\"https://\" + name)\n\tif err != nil || strings.HasSuffix(name, \"/\") || *direct != (url.URL{Scheme: \"https\", Host: direct.Host, Path: direct.Path, RawPath: direct.RawPath}) || direct.RawPath != \"\" || direct.Host == \"\" {\n\t\treturn \"\", nil, fmt.Errorf(\"invalid sumdb name (must be host[/path]): %s %+v\", name, *direct)\n\t}\n\n\t// Determine how to get to database.\n\tvar base *url.URL\n\tif len(key) >= 2 {\n\t\t// Use explicit alternate URL listed in $GOSUMDB,\n\t\t// bypassing both the default URL derivation and any proxies.","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modfetch/sumdb.go#L99-L135","documentation":"This error is thrown when the GOSUMDB environment variable contains more than two whitespace-separated fields. The expected format is 'name [URL]' — at most two tokens: a checksum database name/key and an optional alternate URL. A third or subsequent field means the value is malformed.","triggerScenarios":"GOSUMDB is set with more than two space-separated components, e.g., 'sum.golang.org https://sum.golang.org extra'. The strings.Fields split produces 3+ elements, triggering the length check.","commonSituations":"A user accidentally adds extra arguments to GOSUMDB (e.g., adding flags or comments). A copy-paste error includes trailing text. A script concatenates multiple values into GOSUMDB with spaces. Misunderstanding the format as 'name URL key' instead of 'name [URL]'.","solutions":["Set GOSUMDB to the correct two-field-or-fewer format: 'go env -w GOSUMDB=sum.golang.org' (one field) or 'go env -w GOSUMDB=\"sum.golang.org https://alternate.example.com\"' (two fields).","Remove any trailing or extra text after the URL component.","Reset to default: 'go env -u GOSUMDB'."],"exampleFix":"# before\n$ go env -w GOSUMDB=\"sum.golang.org https://sum.golang.org extra-field\"\n$ go get example.com/mymodule\n# invalid GOSUMDB: too many fields\n\n# after: name only (URL is derived automatically)\n$ go env -w GOSUMDB=sum.golang.org\n$ go get example.com/mymodule","handlingStrategy":"validation","validationCode":"// Validate GOSUMDB format: 1 or 2 whitespace-separated fields\nfunc validateGOSUMDBFormat() error {\n    out, err := exec.Command(\"go\", \"env\", \"GOSUMDB\").Output()\n    if err != nil { return err }\n    val := strings.TrimSpace(string(out))\n    fields := strings.Fields(val)\n    if len(fields) > 2 {\n        return fmt.Errorf(\"GOSUMDB has %d fields, expected at most 2\", len(fields))\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if strings.Contains(stderr, \"invalid GOSUMDB: too many fields\") {\n    // Reset to default\n    // exec.Command(\"go\", \"env\", \"-u\", \"GOSUMDB\")\n}","preventionTips":["GOSUMDB format is: name [URL] — at most 2 fields","Avoid appending comments or extra parameters to GOSUMDB","Use go env -w to set it properly rather than export with potential trailing spaces"],"tags":["go-sumdb","gosumdb","configuration","env-var"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}