golang/go · error
missing key=value
Error message
missing key=value
What it means
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.
Source
Thrown at src/cmd/go/internal/load/godebug.go:31
"sort"
"strconv"
"strings"
"cmd/go/internal/fips140"
"cmd/go/internal/gover"
"cmd/go/internal/modload"
)
var ErrNotGoDebug = errors.New("not //go:debug line")
func ParseGoDebug(text string) (key, value string, err error) {
if !strings.HasPrefix(text, "//go:debug") {
return "", "", ErrNotGoDebug
}
i := strings.IndexAny(text, " \t")
if i < 0 {
if strings.TrimSpace(text) == "//go:debug" {
return "", "", fmt.Errorf("missing key=value")
}
return "", "", ErrNotGoDebug
}
k, v, ok := strings.Cut(strings.TrimSpace(text[i:]), "=")
if !ok {
return "", "", fmt.Errorf("missing key=value")
}
if err := modload.CheckGodebug("//go:debug setting", k, v); err != nil {
return "", "", err
}
return k, v, nil
}
func defaultGODEBUGGoVersion(ld *modload.Loader, p *Package) string {
if !ld.Enabled() {
// GOPATH mode. Use Go 1.20.
return "1.20"
}View on GitHub (pinned to b6b368adc5)
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.
Example fix
// before — empty directive with no arguments //go:debug // after — valid key=value pair //go:debug panicnil=1
Defensive patterns
Strategy: validation
Validate before calling
// Validate //go:debug directive has at least one key=value argument.
func validateGoDebug(text string) error {
if !strings.HasPrefix(text, "//go:debug") {
return nil // not a go:debug line
}
rest := strings.TrimSpace(strings.TrimPrefix(text, "//go:debug"))
if rest == "" {
return fmt.Errorf("//go:debug directive has no key=value pair")
}
return nil
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- missing =<value> in <pattern>=<value>
- missing <pattern> in <pattern>=<value>
- total length of command line and environment variables excee
- gocacheverify=1
- tls: no certificates configured
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/202b3dd521f99a8f.
Report an issue: GitHub.