Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: when a line is set GOPROXY= in the go/env file then GOPROXY is treated as is non-empty #62485

Closed
nemith opened this issue Sep 6, 2023 · 5 comments

Comments

@nemith
Copy link
Contributor

nemith commented Sep 6, 2023

What version of Go are you using (go version)?

$ go version
go version go1.21.0 darwin/arm64

Does this issue reproduce with the latest release?

Yes. I belive this issue is only present on the latest release.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/brandonbennett/Library/Caches/go-build'
GOENV='/Users/brandonbennett/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/brandonbennett/.go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/brandonbennett/.go'
GOPRIVATE=''
GOPROXY=''
GOROOT='/opt/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/xv/k7lms_fn08972kd179h5j1zr0000gp/T/go-build406295014=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I am using go env -w GOPROXY= to try to remove a go/env variable (set it back to default). It updated go/env file with an entry of GOPROXY= .

I then try to use something that needs to proxy like go install -v github.com/cweill/gotests/gotests@v1.6.0

What did you expect to see?

Go should download and install the package with the default GOPROXY settings

What did you see instead?

$ go install -v github.com/cweill/gotests/gotests@v1.6.0
go: github.com/cweill/gotests/gotests@v1.6.0: GOPROXY list is not the empty string, but contains no entries

I think there is probably two potential bugs here:

  1. There should be a way to delete a entry with go env -w
  2. When reading go/env file if the entry exists but is empty, treat it as empty (potentially not a bug but suprising?)
@seankhliao
Copy link
Member

go env -u

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Sep 6, 2023
@nemith
Copy link
Contributor Author

nemith commented Sep 6, 2023

I appreciate pointing out -u but that wasn't what I was reporting.

The bigger issue is that the error message i received didn't match the behavior. In fact I did the go env -w GOPROXY= a long time ago, forgot it was in my file and took a significant part of my day trying to figure out why go env says my GOPROXY is an empty list but I had not set one in my enviroment.

I still think there is at least one (if not two) bugs here.

  1. Empty entries in go/env should be respected as empty (or the error message should be more clear)
  2. go env -w GOPROXY= should be an error

So at very least that error is misleading

$ go env | grep GOPROXY
GOPROXY=''
$ go install -v github.com/cweill/gotests/gotests@v1.6.0
go: github.com/cweill/gotests/gotests@v1.6.0: GOPROXY list is not the empty string, but contains no entries
$ go env -u GOPROXY
$ go env | grep GOPROXY
GOPROXY='https://proxy.golang.org,direct'
$ go install -v github.com/cweill/gotests/gotests@v1.6.0

This didn't happen on Go 1.20.7 and only showed up when I upgraded to Go 1.21.0

Can you please comment on the entire issue? @seankhliao

@seankhliao
Copy link
Member

the defaults are now in GOROOT/go.env, so an empty value corresponds to clearing the values set by the defaults, leaving you with no value set.

@nemith
Copy link
Contributor Author

nemith commented Sep 6, 2023

So is the problem with the GOPROXY checking or at the very least this error message? This error message states that "empty string" should be ok right and in go.env it is an empty string.

GOPROXY list is not the empty string, but contains no entries

Also is there a use case for setting any of the values with no value set? You cannot do the same with os environment variables:

This works fine. So there is a mismatch between how they work in the file vs os level environment variables.

$ GOPROXY= go install -v github.com/cweill/gotests/gotests@v1.6.0

@nemith
Copy link
Contributor Author

nemith commented Sep 7, 2023

I know you probably go through a lot of issues, but I am pretty disappointed with the terse answers and seemingly ignoring half of the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants