1
0
mirror of https://github.com/golang/go synced 2024-11-23 13:50:06 -07:00

cmd/go: include cfg.BuildModReason in 'import lookup disabled' errors

This location was missed in CL 204521.

Updates #33326
Updates #33848

Change-Id: I0ece6d9b37548d8abb54f79c69be5548a0428c76
Reviewed-on: https://go-review.googlesource.com/c/go/+/210341
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Bryan C. Mills 2019-12-06 15:02:28 -05:00
parent df0ac45002
commit 76d2f6cc62
3 changed files with 10 additions and 8 deletions

View File

@ -183,13 +183,14 @@ func Import(path string) (m module.Version, dir string, err error) {
// Look up module containing the package, for addition to the build list. // Look up module containing the package, for addition to the build list.
// Goal is to determine the module, download it to dir, and return m, dir, ErrMissing. // Goal is to determine the module, download it to dir, and return m, dir, ErrMissing.
if cfg.BuildMod == "readonly" { if cfg.BuildMod == "readonly" {
if pathIsStd { var queryErr error
// 'import lookup disabled' would be confusing for standard-library paths, if !pathIsStd {
// since the user probably isn't expecting us to look up a module for if cfg.BuildModReason == "" {
// those anyway. queryErr = fmt.Errorf("import lookup disabled by -mod=%s", cfg.BuildMod)
return module.Version{}, "", &ImportMissingError{Path: path} }
queryErr = fmt.Errorf("import lookup disabled by -mod=%s\n\t(%s)", cfg.BuildMod, cfg.BuildModReason)
} }
return module.Version{}, "", fmt.Errorf("import lookup disabled by -mod=%s", cfg.BuildMod) return module.Version{}, "", &ImportMissingError{Path: path, QueryErr: queryErr}
} }
if modRoot == "" && !allowMissingModuleImports { if modRoot == "" && !allowMissingModuleImports {
return module.Version{}, "", &ImportMissingError{ return module.Version{}, "", &ImportMissingError{

View File

@ -2,7 +2,7 @@
# to individual missing packages. # to individual missing packages.
# Verifies golang.org/issue/34829. # Verifies golang.org/issue/34829.
go list -mod=readonly -e -deps -f '{{if .Error}}{{.ImportPath}}: {{.Error}}{{end}}' . go list -mod=readonly -e -deps -f '{{if .Error}}{{.ImportPath}}: {{.Error}}{{end}}' .
stdout 'example.com/missing: use.go:3:8: import lookup disabled by -mod=readonly' stdout 'example.com/missing: use.go:3:8: cannot find module providing package example.com/missing: import lookup disabled by -mod=readonly'
-- go.mod -- -- go.mod --
module example.com/m module example.com/m

View File

@ -6,13 +6,14 @@ env GOFLAGS=-mod=readonly
go mod edit -fmt go mod edit -fmt
cp go.mod go.mod.empty cp go.mod go.mod.empty
! go list all ! go list all
stderr 'import lookup disabled by -mod=readonly' stderr '^can''t load package: x.go:2:8: cannot find module providing package rsc\.io/quote: import lookup disabled by -mod=readonly'
cmp go.mod go.mod.empty cmp go.mod go.mod.empty
# -mod=readonly should be set implicitly if the go.mod file is read-only # -mod=readonly should be set implicitly if the go.mod file is read-only
chmod 0400 go.mod chmod 0400 go.mod
env GOFLAGS= env GOFLAGS=
! go list all ! 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\n\t\(go.mod file is read-only\.\)$'
chmod 0600 go.mod chmod 0600 go.mod
env GOFLAGS=-mod=readonly env GOFLAGS=-mod=readonly