]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modfetch: treat a missing go.mod file as a “not exist” error
authorBryan C. Mills <bcmills@google.com>
Mon, 24 Jun 2019 14:16:12 +0000 (10:16 -0400)
committerBryan C. Mills <bcmills@google.com>
Mon, 24 Jun 2019 18:27:20 +0000 (18:27 +0000)
If we have found a repository at the requested version but it does not
contain a go.mod file in an appropriate subdirectory, then the module
with the given path does not exist at that version. Therefore, we
should report it with an error equivalent to os.ErrNotExist so that
modload.Query will continue to check other possible module paths.

Updates #27173

Change-Id: Ica73f4bb97f58e611a7f7d38183ee52fef5ee69a
Reviewed-on: https://go-review.googlesource.com/c/go/+/183618
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/internal/modfetch/coderepo.go
src/cmd/go/internal/modfetch/coderepo_test.go
src/cmd/go/testdata/script/mod_invalid_version.txt

index 45243681f8e5acbd885cd60dfa8fa3c467cf18e6..267b76349dd49b2590a140fe4843adecc4ec5326 100644 (file)
@@ -255,7 +255,13 @@ func (r *codeRepo) convert(info *codehost.RevInfo, statVers string) (*RevInfo, e
                        if err != nil {
                                // TODO: It would be nice to return an error like "not a module".
                                // Right now we return "missing go.mod", which is a little confusing.
-                               return nil, err
+                               return nil, &module.ModuleError{
+                                       Path: r.modPath,
+                                       Err: &module.InvalidVersionError{
+                                               Version: info2.Version,
+                                               Err:     notExistError(err.Error()),
+                                       },
+                               }
                        }
                }
 
index bfb1dff3de1961a643f6a6fe4b13d24fda62d1a7..5fc9bc3439722abf9db56a4236c659462a959398 100644 (file)
@@ -638,7 +638,7 @@ var latestTests = []struct {
        {
                vcs:  "git",
                path: "github.com/rsc/vgotest1/subdir",
-               err:  "missing github.com/rsc/vgotest1/subdir/go.mod at revision a08abb797a67",
+               err:  "github.com/rsc/vgotest1/subdir@v0.0.0-20180219223237-a08abb797a67: invalid version: missing github.com/rsc/vgotest1/subdir/go.mod at revision a08abb797a67",
        },
        {
                vcs:     "mod",
index 34cdfe4902442573173c6d0334538c618b25fb1e..2be0d01cce95d124a5077e9f8b83e90a8b1c3026 100644 (file)
@@ -29,10 +29,17 @@ cp go.mod.orig go.mod
 go mod edit -require golang.org/x/text/unicode@v0.0.0-20170915032832-14c0d48ead0c
 cd outside
 ! go list -m golang.org/x/text
-stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text/unicode@v0.0.0-20170915032832-14c0d48ead0c: missing golang.org/x/text/unicode/go.mod at revision 14c0d48ead0c'
+stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text/unicode@v0.0.0-20170915032832-14c0d48ead0c: invalid version: missing golang.org/x/text/unicode/go.mod at revision 14c0d48ead0c'
 cd ..
 ! go list -m golang.org/x/text
-stderr 'golang.org/x/text/unicode@v0.0.0-20170915032832-14c0d48ead0c: missing golang.org/x/text/unicode/go.mod at revision 14c0d48ead0c'
+stderr 'golang.org/x/text/unicode@v0.0.0-20170915032832-14c0d48ead0c: invalid version: missing golang.org/x/text/unicode/go.mod at revision 14c0d48ead0c'
+
+# However, arguments to 'go get' can name packages above the root.
+cp go.mod.orig go.mod
+go get -d golang.org/x/text/unicode@v0.0.0-20170915032832-14c0d48ead0c
+go list -m golang.org/x/text/...
+stdout 'golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c'
+! stdout 'golang.org/x/text/unicode'
 
 # A major version that does not match the module path is invalid.
 cp go.mod.orig go.mod