golang/go · error

key contains comma

Error message

key contains comma

What it means

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.

Source

Thrown at src/cmd/go/internal/modload/init.go:2290

	}

	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 nil
	}
	if godebugs.Lookup(k) != nil {
		return nil
	}
	for _, info := range godebugs.Removed {
		if info.Name == k {

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Open the go.mod or go.work file referenced in the error and find the 'godebug' line with the offending key.
  2. Split any comma-containing key into separate 'godebug' directive lines — one per setting.
  3. Run 'go mod tidy' or 'go work sync' to verify the file parses cleanly after the edit.

Example fix

// before (go.work)
godebug foo,bar=1

// after
godebug foo=1
godebug bar=1
Defensive patterns

Strategy: validation

Validate before calling

// Validate a godebug key before writing it to go.mod/go.work.
func validateGodebugKey(k string) error {
    if strings.ContainsAny(k, " \t") {
        return fmt.Errorf("key contains space")
    }
    if strings.ContainsAny(k, ",") {
        return fmt.Errorf("key contains comma")
    }
    return nil
}

Prevention

When it happens

Trigger: 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".

Common situations: 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.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/980252523afd2cd7. Report an issue: GitHub.