Skip to content

cmd/go: return an early error from queryImport when in vendor mode #58471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/cmd/go/internal/modload/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,12 @@ func queryImport(ctx context.Context, path string, rs *Requirements) (module.Ver
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)
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/go/testdata/script/mod_go_version_missing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ cmp go.mod go.mod.orig

! 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.
Expand Down
4 changes: 1 addition & 3 deletions src/cmd/go/testdata/script/mod_std_vendor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ cd broken
! 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
Expand Down