cmd/go: print the proper error message for setting telemetry vars

For #68960

Change-Id: I5495b3d45ad3817d7edf6336a5e24a331d5cf8d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/609115
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
This commit is contained in:
Michael Matloob 2024-08-28 11:15:32 -04:00
parent e126129d76
commit fe63d483f4
2 changed files with 3 additions and 3 deletions

View File

@ -590,7 +590,7 @@ func getOrigEnv(key string) string {
func checkEnvWrite(key, val string) error {
switch key {
case "GOEXE", "GOGCCFLAGS", "GOHOSTARCH", "GOHOSTOS", "GOMOD", "GOWORK", "GOTOOLDIR", "GOVERSION":
case "GOEXE", "GOGCCFLAGS", "GOHOSTARCH", "GOHOSTOS", "GOMOD", "GOWORK", "GOTOOLDIR", "GOVERSION", "GOTELEMETRY", "GOTELEMETRYDIR":
return fmt.Errorf("%s cannot be modified", key)
case "GOENV", "GODEBUG":
return fmt.Errorf("%s can only be set using the OS environment", key)

View File

@ -46,6 +46,6 @@ go env
stdout 'GOTELEMETRY=''?on''?'
stdout 'GOTELEMETRYDIR=''?'$userconfig'[\\/]go[\\/]telemetry''?'
! go env -w GOTELEMETRY=off
stderr '^go: unknown go command variable GOTELEMETRY$'
stderr '^go: GOTELEMETRY cannot be modified$'
! go env -w GOTELEMETRYDIR=foo
stderr '^go: unknown go command variable GOTELEMETRYDIR$'
stderr '^go: GOTELEMETRYDIR cannot be modified$'