golang/go · error
key contains space
Error message
key contains space
What it means
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.
Source
Thrown at src/cmd/go/internal/modload/init.go:2284
f := func(c rune) bool {
return c > '9' || c < '0'
}
s := strings.FieldsFunc(path, f)
if len(s) > 0 {
m = s[0]
}
m = strings.TrimLeft(m, "0")
if m == "" {
return url + ".v1"
}
return url + ".v" + m
}
func CheckGodebug(verb, k, v string) error {
if strings.ContainsAny(k, " \t") {
return fmt.Errorf("key contains space")
}
if strings.ContainsAny(v, " \t") {
return fmt.Errorf("value contains space")
}
if strings.ContainsAny(k, ",") {
return fmt.Errorf("key contains comma")
}
if strings.ContainsAny(v, ",") {
return fmt.Errorf("value contains comma")
}
if k == "default" {
if !strings.HasPrefix(v, "go") || !gover.IsValid(v[len("go"):]) {
return fmt.Errorf("value for default= must be goVERSION")
}
if gover.Compare(v[len("go"):], gover.Local()) > 0 {
return fmt.Errorf("default=%s too new (toolchain is go%s)", v, gover.Local())
}
return nilView on GitHub (pinned to b6b368adc5)
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.
Example fix
// before (go.mod) godebug panic nil=0 // key 'panic nil' has a space // after godebug panicnil=0
Defensive patterns
Strategy: validation
Validate before calling
// Validate godebug keys for whitespace before commit.
func validGodebugKey(k string) error {
if strings.ContainsAny(k, " \t") {
return errors.New("godebug key contains whitespace")
}
return nil
} Type guard
func isGodebugKeyWellFormed(k string) bool {
return !strings.ContainsAny(k, " \t,") && k != ""
} Try / catch
out, err := exec.Command("go", "build", "./...").CombinedOutput()
if err != nil && bytes.Contains(out, []byte("key contains space")) {
// surface and stop; user must edit the godebug line
return fmt.Errorf("godebug key has whitespace; fix directive: %s", out)
}
return err Prevention
- 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.
When it happens
Trigger: A godebug line like 'godebug my key=value' or 'godebug "key with space"=value' triggers the first check in CheckGodebug.
Common situations: 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).
Related errors
- value contains space
- key contains comma
- value contains comma
- value for default= must be goVERSION
- unknown %s %q
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/0537a3aa90361ded.
Report an issue: GitHub.