Skip to content

Commit 363bcd0

Browse files
author
Bryan C. Mills
committed
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 <[email protected]> Reviewed-by: Michael Matloob <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 7385947 commit 363bcd0

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/cmd/go/internal/modload/import.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ func Import(path string) (m module.Version, dir string, err error) {
184184
if !pathIsStd {
185185
if cfg.BuildModReason == "" {
186186
queryErr = fmt.Errorf("import lookup disabled by -mod=%s", cfg.BuildMod)
187+
} else {
188+
queryErr = fmt.Errorf("import lookup disabled by -mod=%s\n\t(%s)", cfg.BuildMod, cfg.BuildModReason)
187189
}
188-
queryErr = fmt.Errorf("import lookup disabled by -mod=%s\n\t(%s)", cfg.BuildMod, cfg.BuildModReason)
189190
}
190191
return module.Version{}, "", &ImportMissingError{Path: path, QueryErr: queryErr}
191192
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ go mod edit -fmt
77
cp go.mod go.mod.empty
88
! go list all
99
stderr '^can''t load package: x.go:2:8: cannot find module providing package rsc\.io/quote: import lookup disabled by -mod=readonly'
10+
! stderr '\(\)' # If we don't have a reason for -mod=readonly, don't log an empty one.
1011
cmp go.mod go.mod.empty
1112

1213
# -mod=readonly should be set implicitly if the go.mod file is read-only

0 commit comments

Comments
 (0)