aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2020-02-12 13:03:18 -0500
committerBryan C. Mills <bcmills@google.com>2020-02-12 18:22:50 +0000
commit363bcd0068bcc64ec09ab3d09921f559ca6d8070 (patch)
treee61f61877978fd64fcfb2a6f2f1f4f6cd5550477
parent73859478257884608030e5e8d774ffa3321f0ecf (diff)
downloadgo-363bcd0068bcc64ec09ab3d09921f559ca6d8070.tar.gz
go-363bcd0068bcc64ec09ab3d09921f559ca6d8070.zip
cmd/go: eliminate empty '()' when passing -mod=readonly explicitly to 'go list'
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>
-rw-r--r--src/cmd/go/internal/modload/import.go3
-rw-r--r--src/cmd/go/testdata/script/mod_readonly.txt1
2 files changed, 3 insertions, 1 deletions
diff --git a/src/cmd/go/internal/modload/import.go b/src/cmd/go/internal/modload/import.go
index 5906d648b4..d7fca8fd2c 100644
--- a/src/cmd/go/internal/modload/import.go
+++ b/src/cmd/go/internal/modload/import.go
@@ -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}
}
diff --git a/src/cmd/go/testdata/script/mod_readonly.txt b/src/cmd/go/testdata/script/mod_readonly.txt
index 77fc735d57..751f6e645e 100644
--- a/src/cmd/go/testdata/script/mod_readonly.txt
+++ b/src/cmd/go/testdata/script/mod_readonly.txt
@@ -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