1
0
mirror of https://github.com/golang/go synced 2024-11-18 05:54:49 -07:00

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 <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>
This commit is contained in:
Jay Conrod 2020-05-21 10:59:29 -04:00
parent 4abec2a480
commit b2ce3931d8
2 changed files with 14 additions and 1 deletions

View 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"

View 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