]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: replace import error message from goroot to std
authorjchen038 <mfwinds@gmail.com>
Tue, 29 Nov 2022 08:05:54 +0000 (00:05 -0800)
committerGopher Robot <gobot@golang.org>
Mon, 15 May 2023 16:24:01 +0000 (16:24 +0000)
When importing a package that does not exist, it would show goroot error
message and path. We would like to replace goroot with std instead.

Fixes #56965.

Change-Id: I86f8a7fab6555b68f792a3a4686de20d51eced8b
Reviewed-on: https://go-review.googlesource.com/c/go/+/453895
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/cmd/go/internal/modload/import.go
src/cmd/go/testdata/script/cmd_import_error.txt
src/cmd/go/testdata/script/mod_get_replaced.txt
src/cmd/go/testdata/script/mod_goroot_errors.txt
src/cmd/go/testdata/script/mod_issue35270.txt
src/cmd/go/testdata/script/mod_load_missing_std.txt
src/cmd/go/testdata/script/mod_tidy_error.txt
src/cmd/go/testdata/script/mod_vendor.txt
src/go/build/build_test.go

index 86091ea34a535b5d5bd4bc56c62a1d4e14bd3b33..cf56d4e21a55f5d701f82dc5be8981b77206242b 100644 (file)
@@ -57,7 +57,7 @@ type ImportMissingError struct {
 func (e *ImportMissingError) Error() string {
        if e.Module.Path == "" {
                if e.isStd {
-                       msg := fmt.Sprintf("package %s is not in GOROOT (%s)", e.Path, filepath.Join(cfg.GOROOT, "src", e.Path))
+                       msg := fmt.Sprintf("package %s is not in std (%s)", e.Path, filepath.Join(cfg.GOROOT, "src", e.Path))
                        if e.importerGoVersion != "" {
                                msg += fmt.Sprintf("\nnote: imported by a module that requires go %s", e.importerGoVersion)
                        }
index dea76f4d4bf595f8dabfd0071bdeafaceb13dfe8..89e1dbbffdeeb7b36756cafa560369c05b6ea6c5 100644 (file)
@@ -5,10 +5,10 @@ env GO111MODULE=on
 # a clear error in module mode.
 
 ! go list cmd/unknown
-stderr '^package cmd/unknown is not in GOROOT \('$GOROOT'[/\\]src[/\\]cmd[/\\]unknown\)$'
+stderr '^package cmd/unknown is not in std \('$GOROOT'[/\\]src[/\\]cmd[/\\]unknown\)$'
 
 go list -f '{{range .DepsErrors}}{{.Err}}{{end}}' x.go
-stdout '^package cmd/unknown is not in GOROOT \('$GOROOT'[/\\]src[/\\]cmd[/\\]unknown\)$'
+stdout '^package cmd/unknown is not in std \('$GOROOT'[/\\]src[/\\]cmd[/\\]unknown\)$'
 
 -- x.go --
 package x
index b1fc8b80563307cb948b50361507275bd8b578ff..c31d5be4ef9dde3a4301f40607d5e88884b6cd36 100644 (file)
@@ -80,7 +80,7 @@ stdout '^rsc.io/quote v1.4.0'
 cp go.mod.orig go.mod
 
 ! go list example
-stderr '^package example is not in GOROOT \(.*\)$'
+stderr '^package example is not in std \(.*\)$'
 ! go get example
 stderr '^go: malformed module path "example": missing dot in first path element$'
 
index 9d7a94d263b7e228ea00f46ff610146c65a18533..110a196a61fb5b58577f4e8efab961be694f64e9 100644 (file)
@@ -11,24 +11,24 @@ env GO111MODULE=on
 ! go build -mod=readonly nonexist
 ! stderr 'import lookup disabled'
 ! stderr 'missing dot'
-stderr '^package nonexist is not in GOROOT \('$GOROOT'[/\\]src[/\\]nonexist\)$'
+stderr '^package nonexist is not in std \('$GOROOT'[/\\]src[/\\]nonexist\)$'
 
 ! go build nonexist
 ! stderr 'import lookup disabled'
 ! stderr 'missing dot'
-stderr '^package nonexist is not in GOROOT \('$GOROOT'[/\\]src[/\\]nonexist\)$'
+stderr '^package nonexist is not in std \('$GOROOT'[/\\]src[/\\]nonexist\)$'
 
 # Building a nonexistent std package indirectly should also fail usefully.
 
 ! go build -mod=readonly ./importnonexist
 ! stderr 'import lookup disabled'
 ! stderr 'missing dot'
-stderr '^importnonexist[/\\]x.go:2:8: package nonexist is not in GOROOT \('$GOROOT'[/\\]src[/\\]nonexist\)$'
+stderr '^importnonexist[/\\]x.go:2:8: package nonexist is not in std \('$GOROOT'[/\\]src[/\\]nonexist\)$'
 
 ! go build ./importnonexist
 ! stderr 'import lookup disabled'
 ! stderr 'missing dot'
-stderr '^importnonexist[/\\]x.go:2:8: package nonexist is not in GOROOT \('$GOROOT'[/\\]src[/\\]nonexist\)$'
+stderr '^importnonexist[/\\]x.go:2:8: package nonexist is not in std \('$GOROOT'[/\\]src[/\\]nonexist\)$'
 
 # Building an *actual* std package should fail if GOROOT is set to something bogus.
 
@@ -38,7 +38,7 @@ env GOROOT=$WORK/not-a-valid-goroot
 ! go build ./importjson
 ! stderr 'import lookup disabled'
 ! stderr 'missing dot'
-stderr 'importjson[/\\]x.go:2:8: package encoding/json is not in GOROOT \('$WORK'[/\\]not-a-valid-goroot[/\\]src[/\\]encoding[/\\]json\)$'
+stderr 'importjson[/\\]x.go:2:8: package encoding/json is not in std \('$WORK'[/\\]not-a-valid-goroot[/\\]src[/\\]encoding[/\\]json\)$'
 
 -- go.mod --
 module example.com
index 6c2587a12750d606029b905be9066f5a3df4d805..27b922636cd09dde1c8217bb71d7cf9cd3185ca5 100644 (file)
@@ -10,7 +10,7 @@ stderr '^main.go:4:5: ambiguous import: found package image in multiple director
 
 cd ../c
 ! go build -mod=vendor
-stderr 'main.go:4:5: package p is not in GOROOT'
+stderr 'main.go:4:5: package p is not in std'
 
 -- a/go.mod --
 module image
index bd2508a3e38d2d5dfd52fac94199b60fe0e6158b..10633e99e7afd786397c39085d64b8c6f0206f6d 100644 (file)
@@ -2,7 +2,7 @@
 # import is missing. See golang.org/issue/48966.
 
 ! go build .
-stderr '^main.go:3:8: package nonexistent is not in GOROOT \(.*\)$'
+stderr '^main.go:3:8: package nonexistent is not in std \(.*\)$'
 stderr '^note: imported by a module that requires go 1.99999$'
 
 -- go.mod --
index 51fc65fa7a8572ab31ec367b20e08d6ea8002f32..bb1d5e5d6ccc6bdfaf9994a8fd6bdf0d59725c1a 100644 (file)
@@ -4,12 +4,12 @@ env GO111MODULE=on
 # 'go mod tidy' and 'go mod vendor' should not hide loading errors.
 
 ! go mod tidy
-! stderr 'package nonexist is not in GOROOT'
+! stderr 'package nonexist is not in std'
 stderr '^issue27063 imports\n\tnonexist.example.com: cannot find module providing package nonexist.example.com'
 stderr '^issue27063 imports\n\tissue27063/other imports\n\tother.example.com/nonexist: cannot find module providing package other.example.com/nonexist'
 
 ! go mod vendor
-! stderr 'package nonexist is not in GOROOT'
+! stderr 'package nonexist is not in std'
 stderr '^issue27063 imports\n\tnonexist.example.com: no required module provides package nonexist.example.com; to add it:\n\tgo get nonexist.example.com$'
 stderr '^issue27063 imports\n\tissue27063/other imports\n\tother.example.com/nonexist: no required module provides package other.example.com/nonexist; to add it:\n\tgo get other.example.com/nonexist$'
 
index a11d7a1397f8478efb7580901019b1c1c4757006..b02341d58d7ee2c5a4cfb856b4b3f7854ad5bd67 100644 (file)
@@ -55,7 +55,7 @@ stderr 'go: module diamondright: can''t resolve module using the vendor director
 go list -mod=mod -f {{.Dir}} w
 stdout 'src[\\/]w'
 ! go list -mod=vendor -f {{.Dir}} w
-stderr 'package w is not in GOROOT'
+stderr 'package w is not in std'
 
 go list -mod=mod -f {{.Dir}} diamondright
 stdout 'src[\\/]diamondright'
index 34b4f4bca38d96ea7783a20666b3ee8378da8bd6..cef02302362593c56b11ee9b3019a3162bdd1106 100644 (file)
@@ -525,10 +525,10 @@ func TestImportDirNotExist(t *testing.T) {
                                errOk := (err != nil && strings.HasPrefix(err.Error(), "cannot find package"))
                                wantErr := `"cannot find package" error`
                                if test.srcDir == "" {
-                                       if err != nil && strings.Contains(err.Error(), "is not in GOROOT") {
+                                       if err != nil && strings.Contains(err.Error(), "is not in std") {
                                                errOk = true
                                        }
-                                       wantErr = `"cannot find package" or "is not in GOROOT" error`
+                                       wantErr = `"cannot find package" or "is not in std" error`
                                }
                                if !errOk {
                                        t.Errorf("%s got error: %q, want %s", test.label, err, wantErr)