aboutsummaryrefslogtreecommitdiff
path: root/src/go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2020-09-29 17:45:02 -0400
committerBryan C. Mills <bcmills@google.com>2020-10-13 20:13:25 +0000
commit3a65abfbdac7ab29f693d69bd1eb12b2148a11ae (patch)
tree62ce700449d9e498e7dc6af9ef9e19a1ced9652f /src/go
parent076a45acd5b8d2ce08a2dbe898dc9228554db92d (diff)
downloadgo-3a65abfbdac7ab29f693d69bd1eb12b2148a11ae.tar.gz
go-3a65abfbdac7ab29f693d69bd1eb12b2148a11ae.zip
cmd/go: adjust ImportMissingError when module lookup is disabled
Previously, ImportMissingError said "cannot find module providing package …" even when we didn't even attempt to find such a module. Now, we write "no module requirement provides package …" when we did not attempt to identify a suitable module, and suggest either 'go mod tidy' or 'go get -d' as appropriate. Fixes #41576 Change-Id: I979bb999da4066828c54d99a310ea66bb31032ec Reviewed-on: https://go-review.googlesource.com/c/go/+/258298 Trust: Bryan C. Mills <bcmills@google.com> Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/go')
-rw-r--r--src/go/build/build_test.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/go/build/build_test.go b/src/go/build/build_test.go
index 3a4ad22f46..5a4a2d62f5 100644
--- a/src/go/build/build_test.go
+++ b/src/go/build/build_test.go
@@ -612,11 +612,13 @@ func TestImportPackageOutsideModule(t *testing.T) {
ctxt.GOPATH = gopath
ctxt.Dir = filepath.Join(gopath, "src/example.com/p")
- want := "cannot find module providing package"
+ want := "working directory is not part of a module"
if _, err := ctxt.Import("example.com/p", gopath, FindOnly); err == nil {
t.Fatal("importing package when no go.mod is present succeeded unexpectedly")
} else if errStr := err.Error(); !strings.Contains(errStr, want) {
t.Fatalf("error when importing package when no go.mod is present: got %q; want %q", errStr, want)
+ } else {
+ t.Logf(`ctxt.Import("example.com/p", _, FindOnly): %v`, err)
}
}
@@ -677,9 +679,16 @@ func TestMissingImportErrorRepetition(t *testing.T) {
if err == nil {
t.Fatal("unexpected success")
}
+
// Don't count the package path with a URL like https://...?go-get=1.
// See golang.org/issue/35986.
errStr := strings.ReplaceAll(err.Error(), "://"+pkgPath+"?go-get=1", "://...?go-get=1")
+
+ // Also don't count instances in suggested "go get" or similar commands
+ // (see https://golang.org/issue/41576). The suggested command typically
+ // follows a semicolon.
+ errStr = strings.SplitN(errStr, ";", 2)[0]
+
if n := strings.Count(errStr, pkgPath); n != 1 {
t.Fatalf("package path %q appears in error %d times; should appear once\nerror: %v", pkgPath, n, err)
}