{"record":{"id":"202b3dd521f99a8f","repo":"golang/go","slug":"missing-key-value","errorCode":null,"errorMessage":"missing key=value","messagePattern":"missing key=value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/load/godebug.go","lineNumber":31,"sourceCode":"\t\"sort\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"cmd/go/internal/fips140\"\n\t\"cmd/go/internal/gover\"\n\t\"cmd/go/internal/modload\"\n)\n\nvar ErrNotGoDebug = errors.New(\"not //go:debug line\")\n\nfunc ParseGoDebug(text string) (key, value string, err error) {\n\tif !strings.HasPrefix(text, \"//go:debug\") {\n\t\treturn \"\", \"\", ErrNotGoDebug\n\t}\n\ti := strings.IndexAny(text, \" \\t\")\n\tif i < 0 {\n\t\tif strings.TrimSpace(text) == \"//go:debug\" {\n\t\t\treturn \"\", \"\", fmt.Errorf(\"missing key=value\")\n\t\t}\n\t\treturn \"\", \"\", ErrNotGoDebug\n\t}\n\tk, v, ok := strings.Cut(strings.TrimSpace(text[i:]), \"=\")\n\tif !ok {\n\t\treturn \"\", \"\", fmt.Errorf(\"missing key=value\")\n\t}\n\tif err := modload.CheckGodebug(\"//go:debug setting\", k, v); err != nil {\n\t\treturn \"\", \"\", err\n\t}\n\treturn k, v, nil\n}\n\nfunc defaultGODEBUGGoVersion(ld *modload.Loader, p *Package) string {\n\tif !ld.Enabled() {\n\t\t// GOPATH mode. Use Go 1.20.\n\t\treturn \"1.20\"\n\t}","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/load/godebug.go#L13-L49","documentation":"A //go:debug directive in a Go source file consists of the marker '//go:debug' with no whitespace-separated arguments at all. The directive requires at least one key=value pair. This specific variant fires when strings.IndexAny(text, \" \\t\") returns -1 (no space or tab after the prefix) and strings.TrimSpace(text) equals exactly '//go:debug', meaning the line is just the bare directive with nothing following.","triggerScenarios":"Adding '//go:debug' to a Go source file (typically in the main package) with no arguments after it. The ParseGoDebug function finds no whitespace separator and the trimmed text is just the directive marker.","commonSituations":"Writing a //go:debug directive without knowing the required key=value syntax. Template-generated directives that leave the value empty. Accidentally truncating the directive during editing. Copy-pasting from incomplete examples.","solutions":["Add a key=value pair after the directive: //go:debug panicnil=1.","Look up valid GODEBUG keys in the Go documentation (e.g., panicnil, http2client, etc.).","If you don't need the directive, remove the line entirely — an absent directive is not an error."],"exampleFix":"// before — empty directive with no arguments\n//go:debug\n// after — valid key=value pair\n//go:debug panicnil=1","handlingStrategy":"validation","validationCode":"// Validate //go:debug directive has at least one key=value argument.\nfunc validateGoDebug(text string) error {\n    if !strings.HasPrefix(text, \"//go:debug\") {\n        return nil // not a go:debug line\n    }\n    rest := strings.TrimSpace(strings.TrimPrefix(text, \"//go:debug\"))\n    if rest == \"\" {\n        return fmt.Errorf(\"//go:debug directive has no key=value pair\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use the form //go:debug key=value with at least one pair.","Look up valid GODEBUG keys in the Go runtime documentation.","Add a linting rule or pre-commit check for //go:debug directives."],"tags":["go","go-build","godebug","directives","configuration"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}