]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: eliminate empty '()' when passing -mod=readonly explicitly to 'go list'
authorBryan C. Mills <bcmills@google.com>
Wed, 12 Feb 2020 18:03:18 +0000 (13:03 -0500)
committerBryan C. Mills <bcmills@google.com>
Wed, 12 Feb 2020 18:22:50 +0000 (18:22 +0000)
Discovered while investigating #37197.

Updates #33326
Updates #34822

Change-Id: I38b136a4ee762a580a554125066b9778491295f2
Reviewed-on: https://go-review.googlesource.com/c/go/+/219237
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/internal/modload/import.go
src/cmd/go/testdata/script/mod_readonly.txt

index 5906d648b49afdb7065211eb9bec97cc7f1fbbbd..d7fca8fd2c5c9f15b3a348f2dea279ca9757fd50 100644 (file)
@@ -184,8 +184,9 @@ func Import(path string) (m module.Version, dir string, err error) {
                if !pathIsStd {
                        if cfg.BuildModReason == "" {
                                queryErr = fmt.Errorf("import lookup disabled by -mod=%s", cfg.BuildMod)
+                       } else {
+                               queryErr = fmt.Errorf("import lookup disabled by -mod=%s\n\t(%s)", cfg.BuildMod, cfg.BuildModReason)
                        }
-                       queryErr = fmt.Errorf("import lookup disabled by -mod=%s\n\t(%s)", cfg.BuildMod, cfg.BuildModReason)
                }
                return module.Version{}, "", &ImportMissingError{Path: path, QueryErr: queryErr}
        }
index 77fc735d5729a5ca86f190159d466050f9455937..751f6e645e11de78cb2883327118ee047b7406ab 100644 (file)
@@ -7,6 +7,7 @@ go mod edit -fmt
 cp go.mod go.mod.empty
 ! 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'
+! stderr '\(\)' # If we don't have a reason for -mod=readonly, don't log an empty one.
 cmp go.mod go.mod.empty
 
 # -mod=readonly should be set implicitly if the go.mod file is read-only