{"record":{"id":"0537a3aa90361ded","repo":"golang/go","slug":"key-contains-space","errorCode":null,"errorMessage":"key contains space","messagePattern":"key contains space","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/init.go","lineNumber":2284,"sourceCode":"\tf := func(c rune) bool {\n\t\treturn c > '9' || c < '0'\n\t}\n\ts := strings.FieldsFunc(path, f)\n\tif len(s) > 0 {\n\t\tm = s[0]\n\t}\n\n\tm = strings.TrimLeft(m, \"0\")\n\n\tif m == \"\" {\n\t\treturn url + \".v1\"\n\t}\n\treturn url + \".v\" + m\n}\n\nfunc CheckGodebug(verb, k, v string) error {\n\tif strings.ContainsAny(k, \" \\t\") {\n\t\treturn fmt.Errorf(\"key contains space\")\n\t}\n\tif strings.ContainsAny(v, \" \\t\") {\n\t\treturn fmt.Errorf(\"value contains space\")\n\t}\n\tif strings.ContainsAny(k, \",\") {\n\t\treturn fmt.Errorf(\"key contains comma\")\n\t}\n\tif strings.ContainsAny(v, \",\") {\n\t\treturn fmt.Errorf(\"value contains comma\")\n\t}\n\tif k == \"default\" {\n\t\tif !strings.HasPrefix(v, \"go\") || !gover.IsValid(v[len(\"go\"):]) {\n\t\t\treturn fmt.Errorf(\"value for default= must be goVERSION\")\n\t\t}\n\t\tif gover.Compare(v[len(\"go\"):], gover.Local()) > 0 {\n\t\t\treturn fmt.Errorf(\"default=%s too new (toolchain is go%s)\", v, gover.Local())\n\t\t}\n\t\treturn nil","sourceCodeStart":2266,"sourceCodeEnd":2302,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/init.go#L2266-L2302","documentation":"CheckGodebug rejected a godebug directive because the KEY contains a space or tab (strings.ContainsAny(k, \" \\t\")). Applies to both go.mod and go.work godebug lines (the same validator runs for both, via 1066/1070). Directives must be one key=value per line with no internal whitespace in the key.","triggerScenarios":"A godebug line like 'godebug my key=value' or 'godebug \"key with space\"=value' triggers the first check in CheckGodebug.","commonSituations":"Pasting a multi-token GODEBUG env value ('GODEBUG=a b=c') into a godebug directive; hand-typing a descriptive key; misreading the directive grammar (which expects key=value, not a description).","solutions":["Remove whitespace from the key: use a single-token key like 'godebug mykey=value'.","If you meant multiple settings, put one godebug directive per line.","Consult the known GODEBUG keys list and use an exact, single-token name.","Re-run to surface any subsequent value/comma errors."],"exampleFix":"// before (go.mod)\ngodebug panic nil=0      // key 'panic nil' has a space\n\n// after\ngodebug panicnil=0","handlingStrategy":"validation","validationCode":"// Validate godebug keys for whitespace before commit.\nfunc validGodebugKey(k string) error {\n    if strings.ContainsAny(k, \" \\t\") {\n        return errors.New(\"godebug key contains whitespace\")\n    }\n    return nil\n}","typeGuard":"func isGodebugKeyWellFormed(k string) bool {\n    return !strings.ContainsAny(k, \" \\t,\") && k != \"\"\n}","tryCatchPattern":"out, err := exec.Command(\"go\", \"build\", \"./...\").CombinedOutput()\nif err != nil && bytes.Contains(out, []byte(\"key contains space\")) {\n    // surface and stop; user must edit the godebug line\n    return fmt.Errorf(\"godebug key has whitespace; fix directive: %s\", out)\n}\nreturn err","preventionTips":["Use single-token keys only; no spaces or tabs.","Add godebug lines via 'go mod edit -godebug=key=value'.","Lint godebug directives in pre-commit.","Copy keys exactly from the official GODEBUG list."],"tags":["godebug","validation","whitespace","go-mod","go-work"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}