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: 
dd09deec0afecabd1bffc34cfe66db0a8c124fd9
GitHub-Pull-Request: golang/go#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>
 
                return module.Version{}, &ImportMissingError{Path: path, isStd: true}
        }
 
-       if cfg.BuildMod == "readonly" && !allowMissingModuleImports {
+       if (cfg.BuildMod == "readonly" || cfg.BuildMod == "vendor") && !allowMissingModuleImports {
                // In readonly mode, we can't write go.mod, so we shouldn't try to look up
                // the module. If readonly mode was enabled explicitly, include that in
                // the error message.
+               // In vendor mode, we cannot use the network or module cache, so we
+               // shouldn't try to look up the module
                var queryErr error
                if cfg.BuildModExplicit {
                        queryErr = fmt.Errorf("import lookup disabled by -mod=%s", cfg.BuildMod)
 
 
 ! go list -mod=vendor all
 ! stderr '^go: inconsistent vendoring'
-stderr 'go: finding module for package example.com/badedit'
-stderr 'cannot query module due to -mod=vendor'
+stderr 'cannot find module providing package example.com/badedit: import lookup disabled by -mod=vendor'
 
 # When we set -mod=mod, the go version should be updated immediately,
 # to the current version, converting the requirements from eager to lazy.
 
 ! go build -mod=readonly
 stderr 'disabled by -mod=readonly'
 ! go build -mod=vendor
-stderr 'go: finding module for package golang.org/x/net/http2/hpack'
-stderr 'http.go:5:2: cannot query module due to -mod=vendor'
-
+stderr 'http.go:5:2: cannot find module providing package golang.org/x/net/http2/hpack: import lookup disabled by -mod=vendor'
 
 # ...even if they explicitly use the "cmd/vendor/" or "vendor/" prefix.
 cd ../importcmd