]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: report error for empty GOPROXY list
authorJay Conrod <jayconrod@google.com>
Thu, 21 May 2020 14:59:29 +0000 (10:59 -0400)
committerJay Conrod <jayconrod@google.com>
Tue, 26 May 2020 22:28:45 +0000 (22:28 +0000)
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 <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go/internal/modfetch/proxy.go
src/cmd/go/testdata/script/mod_gonoproxy.txt

index 3971598733f4bc12833580fb53b7ae68f45da008..1c35d0b99bd2be203d0735d0a88764fb7856f782 100644 (file)
@@ -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"
index d7848c7d263e7d17de1ba2c3f9b7882f144f2f3f..a9e0ca401089170e0a208c719480b4a16c251ec9 100644 (file)
@@ -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