golang/go · error

value contains space

Error message

value contains space

What it means

CheckGodebug rejected a godebug directive because the VALUE contains a space or tab. This is the second guard in the validator, after the key check. Same root cause class as 1078 but on the right-hand side of the '='.

Source

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

	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 nil
	}
	if godebugs.Lookup(k) != nil {
		return nil

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Strip whitespace from the value: 'godebug key=0' style single-token values.
  2. If multiple values are needed, that setting likely is not supported as multi-valued; check the GODEBUG docs.
  3. Ensure no trailing spaces on the directive line.
  4. Re-run to catch any remaining (comma / unknown key / default=) errors.

Example fix

// before (go.work)
godebug http2tls=strict mode   // value has a space

// after
godebug http2client=0          // a real single-token setting
Defensive patterns

Strategy: validation

Validate before calling

// Validate godebug values for whitespace before commit.
func validGodebugValue(v string) error {
    if strings.ContainsAny(v, " \t") {
        return errors.New("godebug value contains whitespace")
    }
    return nil
}

Type guard

func isGodebugValueWellFormed(v string) bool {
    return !strings.ContainsAny(v, " \t,")
}

Try / catch

out, err := exec.Command("go", "build", "./...").CombinedOutput()
if err != nil && bytes.Contains(out, []byte("value contains space")) {
    return fmt.Errorf("godebug value has whitespace; fix directive: %s", out)
}
return err

Prevention

When it happens

Trigger: A godebug line like 'godebug key=value with space' or 'godebug key="a b"' trips strings.ContainsAny(v, " \t").

Common situations: Trying to embed a descriptive or multi-field value; copy-pasting a shell-quoted GODEBUG value that contained spaces; misunderstanding that godebug values are single tokens.

Related errors


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