Skip to content

Commit b2ce393

Browse files
author
Jay Conrod
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent 4abec2a commit b2ce393

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/cmd/go/internal/modfetch/proxy.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ func proxyList() ([]proxySpec, error) {
171171
fallBackOnError: fallBackOnError,
172172
})
173173
}
174+
175+
if len(proxyOnce.list) == 0 ||
176+
len(proxyOnce.list) == 1 && proxyOnce.list[0].url == "noproxy" {
177+
// There were no proxies, other than the implicit "noproxy" added when
178+
// GONOPROXY is set. This can happen if GOPROXY is a non-empty string
179+
// like "," or " ".
180+
proxyOnce.err = fmt.Errorf("GOPROXY list is not the empty string, but contains no entries")
181+
}
174182
})
175183

176184
return proxyOnce.list, proxyOnce.err
@@ -191,7 +199,7 @@ func TryProxies(f func(proxy string) error) error {
191199
return err
192200
}
193201
if len(proxies) == 0 {
194-
return f("off")
202+
panic("GOPROXY list is empty")
195203
}
196204

197205
// We try to report the most helpful error to the user. "direct" and "noproxy"

src/cmd/go/testdata/script/mod_gonoproxy.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ env GOPRIVATE='*/quote,*/*mple*,golang.org/x'
1818
env GONOPROXY=none # that is, proxy all despite GOPRIVATE
1919
go get rsc.io/quote
2020

21+
# When GOPROXY is not empty but contains no entries, an error should be reported.
22+
env GOPROXY=','
23+
! go get golang.org/x/text
24+
stderr '^go get golang.org/x/text: GOPROXY list is not the empty string, but contains no entries$'
25+
2126
# When GOPROXY=off, fetching modules not matched by GONOPROXY fails.
2227
env GONOPROXY=*/fortune
2328
env GOPROXY=off

0 commit comments

Comments
 (0)