golang/go · error
%s entry cannot contain only space
Error message
%s entry cannot contain only space
What it means
Returned by checkEnvWrite for CC/CXX when quoted.Split succeeds but returns zero tokens (the value was only whitespace). An empty compiler is allowed (val == "" short-circuits earlier), but a whitespace-only value is rejected because it has no executable name.
Source
Thrown at src/cmd/go/internal/envcmd/env.go:686
return fmt.Errorf("GOPATH entry cannot start with shell metacharacter '~': %q", val)
}
if !filepath.IsAbs(val) && val != "" {
return fmt.Errorf("GOPATH entry is relative; must be absolute path: %q", val)
}
case "GOMODCACHE":
if !filepath.IsAbs(val) && val != "" {
return fmt.Errorf("GOMODCACHE entry is relative; must be absolute path: %q", val)
}
case "CC", "CXX":
if val == "" {
break
}
args, err := quoted.Split(val)
if err != nil {
return fmt.Errorf("invalid %s: %v", key, err)
}
if len(args) == 0 {
return fmt.Errorf("%s entry cannot contain only space", key)
}
if !filepath.IsAbs(args[0]) && args[0] != filepath.Base(args[0]) {
return fmt.Errorf("%s entry is relative; must be absolute path: %q", key, args[0])
}
}
if !utf8.ValidString(val) {
return fmt.Errorf("invalid UTF-8 in %s=... value", key)
}
if strings.Contains(val, "\x00") {
return fmt.Errorf("invalid NUL in %s=... value", key)
}
if strings.ContainsAny(val, "\v\r\n") {
return fmt.Errorf("invalid newline in %s=... value", key)
}
return nil
}
View on GitHub (pinned to b6b368adc5)
Solutions
- If you want CGO disabled, set `CGO_ENABLED=0` instead of blanking CC.
- Provide an actual compiler name: `go env -w CC=gcc`.
- If you genuinely want the default, set CC to empty (val == "" is allowed): `go env -w CC=`.
Example fix
# before $ go env -w CC=" " error: CC entry cannot contain only space # after — disable cgo properly $ go env -w CGO_ENABLED=0
Defensive patterns
Strategy: validation
Validate before calling
parts, err := quoted.Split(v)
if err != nil { return err }
if v != "" && len(parts) == 0 {
return fmt.Errorf("CC/CXX value has no tokens")
} Prevention
- Use empty string (not whitespace) to express 'unset'.
- Disable cgo via CGO_ENABLED=0 rather than blanking CC.
- Lint configs for whitespace-only CC/CXX entries.
When it happens
Trigger: `go env -w CC=" "`, `go env -w CXX="\t"`, or any CC/CXX value consisting solely of spaces/tabs.
Common situations: Config generators emitting placeholder whitespace; copy-paste that loses the compiler name but keeps surrounding spaces; scripts concatenating flags onto an empty CC.
Related errors
- invalid %s: %v
- %s entry is relative; must be absolute path: %q
- %s cannot be modified
- %s can only be set using the OS environment
- unknown go command variable %s
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/a8452c3dc5417742.
Report an issue: GitHub.