golang/go · error
value for default= must be goVERSION
Error message
value for default= must be goVERSION
What it means
Thrown by CheckGodebug for the special key 'default'. The default GODEBUG setting specifies which Go language version's defaults to use and must be of the form 'goVERSION' (e.g. 'go1.22'). The check verifies the value has the 'go' prefix via strings.HasPrefix and that the remainder passes gover.IsValid. If either fails, this error is returned.
Source
Thrown at src/cmd/go/internal/modload/init.go:2297
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 nil
}
if godebugs.Lookup(k) != nil {
return nil
}
for _, info := range godebugs.Removed {
if info.Name == k {
if info.Old(v) {
return fmt.Errorf("removed GODEBUG %q set to old value %q (https://go.dev/doc/godebug#go-1%v)", k, v, info.Removed)
}
// Using a removed GODEBUG setting with a non-old value is ok (see go.dev/issue/76163).
return nil
}
}View on GitHub (pinned to b6b368adc5)
Solutions
- Find the 'godebug default=...' line in go.mod or go.work.
- Ensure the value starts with 'go' followed by a valid Go version, e.g. 'go1.22', 'go1.23.1'.
- Run 'go mod tidy' or re-run the go command to confirm the file is accepted.
Example fix
// before godebug default=1.22 // after godebug default=go1.22
Defensive patterns
Strategy: validation
Validate before calling
// Validate a 'default' godebug value.
func validateGodebugDefault(v string) error {
if !strings.HasPrefix(v, "go") {
return fmt.Errorf("value for default= must be goVERSION")
}
// gover.IsValid checks the version portion
if !gover.IsValid(v[len("go"):]) {
return fmt.Errorf("value for default= must be goVERSION")
}
return nil
} Prevention
- Always prefix the default version with 'go' (e.g. 'go1.22', not '1.22').
- Cross-check the default= value against the 'go' directive in go.mod for consistency.
- Use 'go mod edit -godebug=default=go1.22' to set it correctly.
When it happens
Trigger: A godebug directive 'default=X' where X does not start with 'go' or the part after 'go' is not a valid Go version string. Examples: 'default=1.22' (missing 'go' prefix), 'default=goXYZ' (invalid version), 'default=go' (empty version).
Common situations: Typing the version without the 'go' prefix because semver conventions suggest '1.22'. Using a malformed version string. Copy-pasting from documentation that used shorthand.
Related errors
- key contains space
- value contains space
- key contains comma
- value contains comma
- default=%s too new (toolchain is go%s)
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/be2921a5057c6fb7.
Report an issue: GitHub.