]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: include cfg.BuildModReason in 'import lookup disabled' errors
authorBryan C. Mills <bcmills@google.com>
Fri, 6 Dec 2019 20:02:28 +0000 (15:02 -0500)
committerBryan C. Mills <bcmills@google.com>
Fri, 6 Dec 2019 23:44:28 +0000 (23:44 +0000)
This location was missed in CL 204521.

Updates #33326
Updates #33848

Change-Id: I0ece6d9b37548d8abb54f79c69be5548a0428c76
Reviewed-on: https://go-review.googlesource.com/c/go/+/210341
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/modload/import.go
src/cmd/go/testdata/script/mod_list_e_readonly.txt
src/cmd/go/testdata/script/mod_readonly.txt

index 1899abbd8f31ccb1e542de00c43d61c790f3dbff..c7508d170296d31d78b07c73e18cff3965a2db6f 100644 (file)
@@ -183,13 +183,14 @@ func Import(path string) (m module.Version, dir string, err error) {
        // Look up module containing the package, for addition to the build list.
        // Goal is to determine the module, download it to dir, and return m, dir, ErrMissing.
        if cfg.BuildMod == "readonly" {
-               if pathIsStd {
-                       // 'import lookup disabled' would be confusing for standard-library paths,
-                       // since the user probably isn't expecting us to look up a module for
-                       // those anyway.
-                       return module.Version{}, "", &ImportMissingError{Path: path}
+               var queryErr error
+               if !pathIsStd {
+                       if cfg.BuildModReason == "" {
+                               queryErr = fmt.Errorf("import lookup disabled by -mod=%s", cfg.BuildMod)
+                       }
+                       queryErr = fmt.Errorf("import lookup disabled by -mod=%s\n\t(%s)", cfg.BuildMod, cfg.BuildModReason)
                }
-               return module.Version{}, "", fmt.Errorf("import lookup disabled by -mod=%s", cfg.BuildMod)
+               return module.Version{}, "", &ImportMissingError{Path: path, QueryErr: queryErr}
        }
        if modRoot == "" && !allowMissingModuleImports {
                return module.Version{}, "", &ImportMissingError{
index 5baeea24976b476ae2c465801673920c6a9200c8..4969434e52b731ab3f12de70ae9dcfeefb3ac3c7 100644 (file)
@@ -2,7 +2,7 @@
 # to individual missing packages.
 # Verifies golang.org/issue/34829.
 go list -mod=readonly -e -deps -f '{{if .Error}}{{.ImportPath}}: {{.Error}}{{end}}' .
-stdout 'example.com/missing: use.go:3:8: import lookup disabled by -mod=readonly'
+stdout 'example.com/missing: use.go:3:8: cannot find module providing package example.com/missing: import lookup disabled by -mod=readonly'
 
 -- go.mod --
 module example.com/m
index 1c89b49f51151532643c342ae7ff59f521130744..1d1771e9cc04911e90e21bee21a062c872ea7f18 100644 (file)
@@ -6,13 +6,14 @@ env GOFLAGS=-mod=readonly
 go mod edit -fmt
 cp go.mod go.mod.empty
 ! go list all
-stderr 'import lookup disabled by -mod=readonly'
+stderr '^can''t load package: x.go:2:8: cannot find module providing package rsc\.io/quote: import lookup disabled by -mod=readonly'
 cmp go.mod go.mod.empty
 
 # -mod=readonly should be set implicitly if the go.mod file is read-only
 chmod 0400 go.mod
 env GOFLAGS=
 ! go list all
+stderr '^can''t load package: x.go:2:8: cannot find module providing package rsc\.io/quote: import lookup disabled by -mod=readonly\n\t\(go.mod file is read-only\.\)$'
 
 chmod 0600 go.mod
 env GOFLAGS=-mod=readonly