Skip to content

Commit 1b896bf

Browse files
jchen038gopherbot
authored andcommitted
cmd/go/internal/modload: replace import error message from goroot to std
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>
1 parent 0e7a250 commit 1b896bf

File tree

9 files changed

+16
-16
lines changed

9 files changed

+16
-16
lines changed

src/cmd/go/internal/modload/import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type ImportMissingError struct {
5757
func (e *ImportMissingError) Error() string {
5858
if e.Module.Path == "" {
5959
if e.isStd {
60-
msg := fmt.Sprintf("package %s is not in GOROOT (%s)", e.Path, filepath.Join(cfg.GOROOT, "src", e.Path))
60+
msg := fmt.Sprintf("package %s is not in std (%s)", e.Path, filepath.Join(cfg.GOROOT, "src", e.Path))
6161
if e.importerGoVersion != "" {
6262
msg += fmt.Sprintf("\nnote: imported by a module that requires go %s", e.importerGoVersion)
6363
}

src/cmd/go/testdata/script/cmd_import_error.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ env GO111MODULE=on
55
# a clear error in module mode.
66

77
! go list cmd/unknown
8-
stderr '^package cmd/unknown is not in GOROOT \('$GOROOT'[/\\]src[/\\]cmd[/\\]unknown\)$'
8+
stderr '^package cmd/unknown is not in std \('$GOROOT'[/\\]src[/\\]cmd[/\\]unknown\)$'
99

1010
go list -f '{{range .DepsErrors}}{{.Err}}{{end}}' x.go
11-
stdout '^package cmd/unknown is not in GOROOT \('$GOROOT'[/\\]src[/\\]cmd[/\\]unknown\)$'
11+
stdout '^package cmd/unknown is not in std \('$GOROOT'[/\\]src[/\\]cmd[/\\]unknown\)$'
1212

1313
-- x.go --
1414
package x

src/cmd/go/testdata/script/mod_get_replaced.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ stdout '^rsc.io/quote v1.4.0'
8080
cp go.mod.orig go.mod
8181

8282
! go list example
83-
stderr '^package example is not in GOROOT \(.*\)$'
83+
stderr '^package example is not in std \(.*\)$'
8484
! go get example
8585
stderr '^go: malformed module path "example": missing dot in first path element$'
8686

src/cmd/go/testdata/script/mod_goroot_errors.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ env GO111MODULE=on
1111
! go build -mod=readonly nonexist
1212
! stderr 'import lookup disabled'
1313
! stderr 'missing dot'
14-
stderr '^package nonexist is not in GOROOT \('$GOROOT'[/\\]src[/\\]nonexist\)$'
14+
stderr '^package nonexist is not in std \('$GOROOT'[/\\]src[/\\]nonexist\)$'
1515

1616
! go build nonexist
1717
! stderr 'import lookup disabled'
1818
! stderr 'missing dot'
19-
stderr '^package nonexist is not in GOROOT \('$GOROOT'[/\\]src[/\\]nonexist\)$'
19+
stderr '^package nonexist is not in std \('$GOROOT'[/\\]src[/\\]nonexist\)$'
2020

2121
# Building a nonexistent std package indirectly should also fail usefully.
2222

2323
! go build -mod=readonly ./importnonexist
2424
! stderr 'import lookup disabled'
2525
! stderr 'missing dot'
26-
stderr '^importnonexist[/\\]x.go:2:8: package nonexist is not in GOROOT \('$GOROOT'[/\\]src[/\\]nonexist\)$'
26+
stderr '^importnonexist[/\\]x.go:2:8: package nonexist is not in std \('$GOROOT'[/\\]src[/\\]nonexist\)$'
2727

2828
! go build ./importnonexist
2929
! stderr 'import lookup disabled'
3030
! stderr 'missing dot'
31-
stderr '^importnonexist[/\\]x.go:2:8: package nonexist is not in GOROOT \('$GOROOT'[/\\]src[/\\]nonexist\)$'
31+
stderr '^importnonexist[/\\]x.go:2:8: package nonexist is not in std \('$GOROOT'[/\\]src[/\\]nonexist\)$'
3232

3333
# Building an *actual* std package should fail if GOROOT is set to something bogus.
3434

@@ -38,7 +38,7 @@ env GOROOT=$WORK/not-a-valid-goroot
3838
! go build ./importjson
3939
! stderr 'import lookup disabled'
4040
! stderr 'missing dot'
41-
stderr 'importjson[/\\]x.go:2:8: package encoding/json is not in GOROOT \('$WORK'[/\\]not-a-valid-goroot[/\\]src[/\\]encoding[/\\]json\)$'
41+
stderr 'importjson[/\\]x.go:2:8: package encoding/json is not in std \('$WORK'[/\\]not-a-valid-goroot[/\\]src[/\\]encoding[/\\]json\)$'
4242

4343
-- go.mod --
4444
module example.com

src/cmd/go/testdata/script/mod_issue35270.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ stderr '^main.go:4:5: ambiguous import: found package image in multiple director
1010

1111
cd ../c
1212
! go build -mod=vendor
13-
stderr 'main.go:4:5: package p is not in GOROOT'
13+
stderr 'main.go:4:5: package p is not in std'
1414

1515
-- a/go.mod --
1616
module image

src/cmd/go/testdata/script/mod_load_missing_std.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# import is missing. See golang.org/issue/48966.
33

44
! go build .
5-
stderr '^main.go:3:8: package nonexistent is not in GOROOT \(.*\)$'
5+
stderr '^main.go:3:8: package nonexistent is not in std \(.*\)$'
66
stderr '^note: imported by a module that requires go 1.99999$'
77

88
-- go.mod --

src/cmd/go/testdata/script/mod_tidy_error.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ env GO111MODULE=on
44
# 'go mod tidy' and 'go mod vendor' should not hide loading errors.
55

66
! go mod tidy
7-
! stderr 'package nonexist is not in GOROOT'
7+
! stderr 'package nonexist is not in std'
88
stderr '^issue27063 imports\n\tnonexist.example.com: cannot find module providing package nonexist.example.com'
99
stderr '^issue27063 imports\n\tissue27063/other imports\n\tother.example.com/nonexist: cannot find module providing package other.example.com/nonexist'
1010

1111
! go mod vendor
12-
! stderr 'package nonexist is not in GOROOT'
12+
! stderr 'package nonexist is not in std'
1313
stderr '^issue27063 imports\n\tnonexist.example.com: no required module provides package nonexist.example.com; to add it:\n\tgo get nonexist.example.com$'
1414
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$'
1515

src/cmd/go/testdata/script/mod_vendor.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ stderr 'go: module diamondright: can''t resolve module using the vendor director
5555
go list -mod=mod -f {{.Dir}} w
5656
stdout 'src[\\/]w'
5757
! go list -mod=vendor -f {{.Dir}} w
58-
stderr 'package w is not in GOROOT'
58+
stderr 'package w is not in std'
5959

6060
go list -mod=mod -f {{.Dir}} diamondright
6161
stdout 'src[\\/]diamondright'

src/go/build/build_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,10 @@ func TestImportDirNotExist(t *testing.T) {
525525
errOk := (err != nil && strings.HasPrefix(err.Error(), "cannot find package"))
526526
wantErr := `"cannot find package" error`
527527
if test.srcDir == "" {
528-
if err != nil && strings.Contains(err.Error(), "is not in GOROOT") {
528+
if err != nil && strings.Contains(err.Error(), "is not in std") {
529529
errOk = true
530530
}
531-
wantErr = `"cannot find package" or "is not in GOROOT" error`
531+
wantErr = `"cannot find package" or "is not in std" error`
532532
}
533533
if !errOk {
534534
t.Errorf("%s got error: %q, want %s", test.label, err, wantErr)

0 commit comments

Comments
 (0)