golang/go · error

value contains comma

Error message

value contains comma

What it means

Thrown by CheckGodebug when a GODEBUG value (the part after '=') contains a comma. Since the go.mod/go.work godebug directive format uses commas only as separators between multiple key=value pairs on the same conceptual list, a value with a comma would be misinterpreted as delimiting a new entry. This is checked after the key-space and value-space checks but before the 'default=' special-case.

Source

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

	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 {
			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)
			}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Locate the godebug line in go.mod/go.work whose value contains a comma.
  2. Determine whether the comma was intended as a list separator — if so, use separate godebug lines for each setting instead.
  3. If the value genuinely needs a comma, verify the GODEBUG setting name is valid and check its documented value format at https://go.dev/doc/godebug.

Example fix

// before (go.mod)
godebug asn1tag=0,1

// after
godebug asn1tag=0
godebug otherflag=1
Defensive patterns

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: A godebug directive in go.mod or go.work has a value like 'godebug somekey=1,2' where the value portion after '=' contains a comma. The check strings.ContainsAny(v, ",") returns true.

Common situations: Attempting to pass a multi-valued setting (e.g. a list) into a single GODEBUG value. Confusing the environment variable GODEBUG syntax (comma-separated) with the go.mod directive syntax (one per line).

Related errors


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