Skip to content

Commit c17f805

Browse files
rohnnyjoygopherbot
authored andcommitted
cmd/go: return an early error from queryImport when in vendor mode
The current behavior for -mod=vendor is to let QueryPackages run and fail from queryImport: "cannot query module due to -mod=vendor". This has the side effect of allowing "go: finding module for package" to be printed to stderr. Instead of this, return an error before running QueryPackages. Fixes #58417 Change-Id: Idc0ed33d1dd1bd185348da3a18ba8eb2dd225909 GitHub-Last-Rev: dd09dee GitHub-Pull-Request: #58471 Reviewed-on: https://go-review.googlesource.com/c/go/+/467517 Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
1 parent 4a1829b commit c17f805

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,12 @@ func queryImport(ctx context.Context, path string, rs *Requirements) (module.Ver
546546
return module.Version{}, &ImportMissingError{Path: path, isStd: true}
547547
}
548548

549-
if cfg.BuildMod == "readonly" && !allowMissingModuleImports {
549+
if (cfg.BuildMod == "readonly" || cfg.BuildMod == "vendor") && !allowMissingModuleImports {
550550
// In readonly mode, we can't write go.mod, so we shouldn't try to look up
551551
// the module. If readonly mode was enabled explicitly, include that in
552552
// the error message.
553+
// In vendor mode, we cannot use the network or module cache, so we
554+
// shouldn't try to look up the module
553555
var queryErr error
554556
if cfg.BuildModExplicit {
555557
queryErr = fmt.Errorf("import lookup disabled by -mod=%s", cfg.BuildMod)

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ cmp go.mod go.mod.orig
2727

2828
! go list -mod=vendor all
2929
! stderr '^go: inconsistent vendoring'
30-
stderr 'go: finding module for package example.com/badedit'
31-
stderr 'cannot query module due to -mod=vendor'
30+
stderr 'cannot find module providing package example.com/badedit: import lookup disabled by -mod=vendor'
3231

3332
# When we set -mod=mod, the go version should be updated immediately,
3433
# to the current version, converting the requirements from eager to lazy.

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ cd broken
2222
! go build -mod=readonly
2323
stderr 'disabled by -mod=readonly'
2424
! go build -mod=vendor
25-
stderr 'go: finding module for package golang.org/x/net/http2/hpack'
26-
stderr 'http.go:5:2: cannot query module due to -mod=vendor'
27-
25+
stderr 'http.go:5:2: cannot find module providing package golang.org/x/net/http2/hpack: import lookup disabled by -mod=vendor'
2826

2927
# ...even if they explicitly use the "cmd/vendor/" or "vendor/" prefix.
3028
cd ../importcmd

0 commit comments

Comments
 (0)