{"record":{"id":"c28a83dde98933be","repo":"golang/go","slug":"unknown-go-command-variable-s","errorCode":null,"errorMessage":"unknown go command variable %s","messagePattern":"unknown go command variable (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/envcmd/env.go","lineNumber":653,"sourceCode":"\t\t\"GOGCCFLAGS\",\n\t\t\"GOHOSTARCH\",\n\t\t\"GOHOSTOS\",\n\t\t\"GOMOD\",\n\t\t\"GOROOT\",\n\t\t\"GOTELEMETRY\",\n\t\t\"GOTELEMETRYDIR\",\n\t\t\"GOTOOLDIR\",\n\t\t\"GOVERSION\",\n\t\t\"GOWORK\":\n\t\treturn fmt.Errorf(\"%s cannot be modified\", key)\n\tcase \"GOENV\", \"GODEBUG\":\n\t\treturn fmt.Errorf(\"%s can only be set using the OS environment\", key)\n\t}\n\n\t// To catch typos and the like, check that we know the variable.\n\t// If it's already in the env file, we assume it's known.\n\tif !cfg.CanGetenv(key) {\n\t\treturn fmt.Errorf(\"unknown go command variable %s\", key)\n\t}\n\n\t// Some variables can only have one of a few valid values. If set to an\n\t// invalid value, the next cmd/go invocation might fail immediately,\n\t// even 'go env -w' itself.\n\tswitch key {\n\tcase \"GO111MODULE\":\n\t\tswitch val {\n\t\tcase \"\", \"auto\", \"on\", \"off\":\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"invalid %s value %q\", key, val)\n\t\t}\n\tcase \"GOPATH\":\n\t\tif strings.HasPrefix(val, \"~\") {\n\t\t\treturn fmt.Errorf(\"GOPATH entry cannot start with shell metacharacter '~': %q\", val)\n\t\t}\n\t\tif !filepath.IsAbs(val) && val != \"\" {\n\t\t\treturn fmt.Errorf(\"GOPATH entry is relative; must be absolute path: %q\", val)","sourceCodeStart":635,"sourceCodeEnd":671,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/envcmd/env.go#L635-L671","documentation":"Returned by checkEnvWrite when the key passed to `go env -w` is not a recognised go command variable (cfg.CanGetenv(key) is false and the key is not already present in the env file). It catches typos and arbitrary names before they are written to the env config.","triggerScenarios":"`go env -w TYPO=1`, `go env -w MYVAR=foo`, or any key not in cfg.CanGetenv's known set and not already in the user's go env file.","commonSituations":"Typos like GOPRXY instead of GOPROXY; copying a shell var name into `go env -w`; using a var name from a newer/older Go version not supported by this toolchain.","solutions":["Check the spelling against `go help environment` and `go env -json` output.","Run `go env` to list currently-known keys and match your key exactly (case-sensitive).","If the variable is from a newer Go release, upgrade the toolchain (GOTOOLCHAIN=auto or install a newer Go).","Confirm the variable is a go-command variable at all — shell-only vars (e.g. SHELL, PATH) do not belong in `go env -w`."],"exampleFix":"# before\n$ go env -w GOPRXY=https://proxy.golang.org\nerror: unknown go command variable GOPRXY\n# after — correct spelling\n$ go env -w GOPROXY=https://proxy.golang.org,direct","handlingStrategy":"validation","validationCode":"// Build the set of known go variables from `go env -json`, then validate.\nfunc isValidGoVar(key string, known []string) bool {\n    for k := range known { if k == key { return true } }\n    return false\n}\nif !isValidGoVar(key, knownVars) {\n    return fmt.Errorf(\"refusing `go env -w %s`: unknown variable\", key)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `go env` and copy variable names verbatim — case-sensitive.","Upgrade the toolchain before assuming a newer variable exists.","Add a CI lint that fails on unknown keys in your env-wrapping scripts."],"tags":["config","env","validation","typo"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}