{"record":{"id":"980252523afd2cd7","repo":"golang/go","slug":"key-contains-comma","errorCode":null,"errorMessage":"key contains comma","messagePattern":"key contains comma","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/init.go","lineNumber":2290,"sourceCode":"\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\n\t}\n\tif godebugs.Lookup(k) != nil {\n\t\treturn nil\n\t}\n\tfor _, info := range godebugs.Removed {\n\t\tif info.Name == k {","sourceCodeStart":2272,"sourceCodeEnd":2308,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/init.go#L2272-L2308","documentation":"Thrown by CheckGodebug when validating a GODEBUG key from go.mod or go.work. GODEBUG entries are comma-separated key=value pairs (e.g. 'godebug paniconfatal=1,gctrace=2'), so a key containing a comma would corrupt the parsing of subsequent entries. The check uses strings.ContainsAny(k, \",\") to reject any key with a comma character before further validation proceeds.","triggerScenarios":"A go.mod or go.work file contains a 'godebug' directive line where the key portion (before '=') contains a comma, e.g. 'godebug foo,bar=1'. Called from go.work parsing at init.go:826 and go.mod parsing at init.go:1065 with verb=\"godebug\".","commonSituations":"Hand-editing a go.mod/go.work and accidentally putting two settings on one line without proper syntax. Migrating from the GODEBUG environment variable (which uses commas as separators) to the godebug directive and not realizing the directive syntax requires one key=value per line.","solutions":["Open the go.mod or go.work file referenced in the error and find the 'godebug' line with the offending key.","Split any comma-containing key into separate 'godebug' directive lines — one per setting.","Run 'go mod tidy' or 'go work sync' to verify the file parses cleanly after the edit."],"exampleFix":"// before (go.work)\ngodebug foo,bar=1\n\n// after\ngodebug foo=1\ngodebug bar=1","handlingStrategy":"validation","validationCode":"// Validate a godebug key before writing it to go.mod/go.work.\nfunc validateGodebugKey(k string) error {\n    if strings.ContainsAny(k, \" \\t\") {\n        return fmt.Errorf(\"key contains space\")\n    }\n    if strings.ContainsAny(k, \",\") {\n        return fmt.Errorf(\"key contains comma\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 'go mod edit -godebug=key=value' rather than hand-editing go.mod to avoid syntax errors.","Never put multiple GODEBUG settings on one line in the godebug directive — one key=value per line.","Run 'go mod tidy' after editing go.mod/go.work to catch directive syntax errors early."],"tags":["godebug","go-mod","go-work","validation","config-syntax"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}