golang/go · error

invalid value

Error message

invalid %s value %q

What it means

Returned by checkEnvWrite's value-validation switch when a key that only accepts enumerated values is given something outside the allowed set. Currently fires for GO111MODULE with values other than "", "auto", "on", "off".

Solutions

  1. Use one of the documented values: "", "auto", "on", or "off".
  2. In module-aware Go (1.16+), prefer leaving GO111MODULE unset (defaults to on) rather than forcing a value.
  3. If migrating from GOPATH mode, set GO111MODULE=on explicitly only while transitioning.

Example fix

# before
$ go env -w GO111MODULE=true
error: invalid GO111MODULE value "true"
# after
$ go env -w GO111MODULE=on
Defensive patterns

Strategy: validation

Validate before calling

var go111Valid = map[string]bool{"": true, "auto": true, "on": true, "off": true}
if key == "GO111MODULE" && !go111Valid[val] {
    return fmt.Errorf("GO111MODULE must be one of '', auto, on, off; got %q", val)
}

Prevention

When it happens

Trigger: `go env -w GO111MODULE=enable`, `go env -w GO111MODULE=yes`, `go env -w GO111MODULE=true`, or any value not in {"", auto, on, off}.

Common situations: Users assuming boolean syntax (true/false, yes/no, 1/0) for GO111MODULE; copy-paste from tutorials using non-canonical values; migration scripts that blindly forward old config.

Related errors


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

Appendix: source

Thrown at src/cmd/go/internal/envcmd/env.go:664

	case "GOENV", "GODEBUG":
		return fmt.Errorf("%s can only be set using the OS environment", key)
	}

	// To catch typos and the like, check that we know the variable.
	// If it's already in the env file, we assume it's known.
	if !cfg.CanGetenv(key) {
		return fmt.Errorf("unknown go command variable %s", key)
	}

	// Some variables can only have one of a few valid values. If set to an
	// invalid value, the next cmd/go invocation might fail immediately,
	// even 'go env -w' itself.
	switch key {
	case "GO111MODULE":
		switch val {
		case "", "auto", "on", "off":
		default:
			return fmt.Errorf("invalid %s value %q", key, val)
		}
	case "GOPATH":
		if strings.HasPrefix(val, "~") {
			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 {

View on GitHub (pinned to b6b368adc5)