From: Jay Conrod Date: Thu, 21 May 2020 14:59:29 +0000 (-0400) Subject: cmd/go: report error for empty GOPROXY list X-Git-Tag: go1.15beta1~105 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b2ce3931d8d34ffe3fbed0d9eed2676d916e5431;p=gostls13.git cmd/go: report error for empty GOPROXY list If GOPROXY is "", we set it to the default value, "https://proxy.golang.org,direct". However, if GOPROXY is a non-empty string that doesn't contain any URLs or keywords, we treat it as either "off" or "noproxy", which can lead to some strange errors. This change reports an error for this kind of GOPROXY value. For #39180 Change-Id: If2e6e39d6f74c708e5ec8f90e9d4880e0e91894f Reviewed-on: https://go-review.googlesource.com/c/go/+/234857 Run-TryBot: Jay Conrod TryBot-Result: Gobot Gobot Reviewed-by: Bryan C. Mills Reviewed-by: Michael Matloob --- diff --git a/src/cmd/go/internal/modfetch/proxy.go b/src/cmd/go/internal/modfetch/proxy.go index 3971598733..1c35d0b99b 100644 --- a/src/cmd/go/internal/modfetch/proxy.go +++ b/src/cmd/go/internal/modfetch/proxy.go @@ -171,6 +171,14 @@ func proxyList() ([]proxySpec, error) { fallBackOnError: fallBackOnError, }) } + + if len(proxyOnce.list) == 0 || + len(proxyOnce.list) == 1 && proxyOnce.list[0].url == "noproxy" { + // There were no proxies, other than the implicit "noproxy" added when + // GONOPROXY is set. This can happen if GOPROXY is a non-empty string + // like "," or " ". + proxyOnce.err = fmt.Errorf("GOPROXY list is not the empty string, but contains no entries") + } }) return proxyOnce.list, proxyOnce.err @@ -191,7 +199,7 @@ func TryProxies(f func(proxy string) error) error { return err } if len(proxies) == 0 { - return f("off") + panic("GOPROXY list is empty") } // We try to report the most helpful error to the user. "direct" and "noproxy" diff --git a/src/cmd/go/testdata/script/mod_gonoproxy.txt b/src/cmd/go/testdata/script/mod_gonoproxy.txt index d7848c7d26..a9e0ca4010 100644 --- a/src/cmd/go/testdata/script/mod_gonoproxy.txt +++ b/src/cmd/go/testdata/script/mod_gonoproxy.txt @@ -18,6 +18,11 @@ env GOPRIVATE='*/quote,*/*mple*,golang.org/x' env GONOPROXY=none # that is, proxy all despite GOPRIVATE go get rsc.io/quote +# When GOPROXY is not empty but contains no entries, an error should be reported. +env GOPROXY=',' +! go get golang.org/x/text +stderr '^go get golang.org/x/text: GOPROXY list is not the empty string, but contains no entries$' + # When GOPROXY=off, fetching modules not matched by GONOPROXY fails. env GONOPROXY=*/fortune env GOPROXY=off