Skip to content

Commit 4b41f7f

Browse files
author
Bryan C. Mills
committed
cmd/go/internal/modfetch: halt proxy fallback if the proxy returns a non-404/410 response for @latest
The @latest proxy endpoint is optional. If a proxy returns a 404 for it, and returns an @v/list with no matching versions, then we should allow module lookup to try other module paths. However, if the proxy returns some other error (say, a 403 or 505), then the result of the lookup is ambiguous, and we should report the actual error rather than "no matching versions for query". (This fix was prompted by discussion with Dmitri on CL 183619.) Updates #32715 Updates #26334 Change-Id: I6d510a5ac24d48d9bc5037c3c747ac50695c663f Reviewed-on: https://go-review.googlesource.com/c/go/+/183845 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 070e2dd commit 4b41f7f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ func (p *proxyRepo) Stat(rev string) (*RevInfo, error) {
345345
func (p *proxyRepo) Latest() (*RevInfo, error) {
346346
data, err := p.getBytes("@latest")
347347
if err != nil {
348-
// TODO return err if not 404
348+
if !errors.Is(err, os.ErrNotExist) {
349+
return nil, p.versionError("", err)
350+
}
349351
return p.latest()
350352
}
351353
info := new(RevInfo)

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ go list -m example.com/join/...
2828
! stdout 'example.com/join/subpkg'
2929
stdout 'example.com/join v1.1.0'
3030

31+
# If the proxy provides an empty @v/list but rejects @latest with
32+
# some other explicit error (for example, a "permission denied" error),
33+
# that error should be reported to the user (and override a successful
34+
# result for other possible module paths).
35+
#
36+
# Depending on how the specific platform enforces permissions, the 'go get' may
37+
# fail either due to the intended permission error or due to a parse error.
38+
# We accept either failure message.
39+
env GOPROXY=file:///$WORK/gatekeeper
40+
chmod 0000 $WORK/gatekeeper/example.com/join/subpkg/@latest
41+
cp go.mod.orig go.mod
42+
! go get -d example.com/join/subpkg
43+
stderr 'go get example.com/join/subpkg: module example.com/join/subpkg: (invalid character .+|reading file://.*/gatekeeper/example.com/join/subpkg/@latest: .+)'
44+
3145
-- go.mod.orig --
3246
module example.com/othermodule
3347
go 1.13
@@ -50,3 +64,10 @@ v1.0.0-does-not-exist
5064
v1.1.0
5165
-- $WORK/notfound/example.com/join/@v/v1.1.0.info --
5266
{"Version": "v1.1.0"}
67+
-- $WORK/gatekeeper/example.com/join/subpkg/@v/list --
68+
-- $WORK/gatekeeper/example.com/join/subpkg/@latest --
69+
ERROR: Latest version is forbidden.
70+
-- $WORK/gatekeeper/example.com/join/@v/list --
71+
v1.1.0
72+
-- $WORK/gatekeeper/example.com/join/@v/v1.1.0.info --
73+
{"Version": "v1.1.0"}

0 commit comments

Comments
 (0)