[go] cmd/go: better error message for when line having '@'

147 views
Skip to first unread message

jiahua wang (Gerrit)

unread,
Jan 26, 2022, 10:09:27 PM1/26/22
to goph...@pubsubhelper.golang.org, jiahua wang, golang-co...@googlegroups.com

jiahua wang has uploaded this change for review.

View Change

cmd/go: better error message for when line having '@'

Fix #50713

Change-Id: Iefb0bd30f6dee3feef46fb9369b9941cc2de2263
---
M src/cmd/go/go_test.go
M src/cmd/go/internal/load/pkg.go
M src/cmd/go/testdata/script/mod_versions.txt
3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go
index 7aaec4e..6918a69 100644
--- a/src/cmd/go/go_test.go
+++ b/src/cmd/go/go_test.go
@@ -2658,12 +2658,12 @@
tg.tempFile("src/@x/x.go", "package x\n")
tg.setenv("GOPATH", tg.path("."))
tg.runFail("build", "@x")
- tg.grepStderr("invalid input directory name \"@x\"|can only use path@version syntax with 'go get' and 'go install' in module-aware mode", "did not reject @x directory")
+ tg.grepStderr("invalid input directory name \"@x\"|can only use path@version syntax with 'go get' and 'go install' and 'go list -m ...' in module-aware mode", "did not reject @x directory")

tg.tempFile("src/@x/y/y.go", "package y\n")
tg.setenv("GOPATH", tg.path("."))
tg.runFail("build", "@x/y")
- tg.grepStderr("invalid import path \"@x/y\"|can only use path@version syntax with 'go get' and 'go install' in module-aware mode", "did not reject @x/y import path")
+ tg.grepStderr("invalid import path \"@x/y\"|can only use path@version syntax with 'go get' and 'go install' and 'go list -m ...' in module-aware mode", "did not reject @x/y import path")

tg.tempFile("src/-x/x.go", "package x\n")
tg.setenv("GOPATH", tg.path("."))
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index fca9d5a..5724274 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -796,7 +796,7 @@
}

if strings.Contains(path, "@") {
- return nil, false, errors.New("can only use path@version syntax with 'go get' and 'go install' in module-aware mode")
+ return nil, false, errors.New("can only use path@version syntax with 'go get' and 'go install' and 'go list -m ...' in module-aware mode")
}

// Determine canonical package path and directory.
diff --git a/src/cmd/go/testdata/script/mod_versions.txt b/src/cmd/go/testdata/script/mod_versions.txt
index 9e6322b..efdfa9a 100644
--- a/src/cmd/go/testdata/script/mod_versions.txt
+++ b/src/cmd/go/testdata/script/mod_versions.txt
@@ -3,12 +3,12 @@
! go get rsc.io/qu...@v1.5.1
stderr '^go: can only use path@version syntax with ''go get'' and ''go install'' in module-aware mode$'
! go build rsc.io/qu...@v1.5.1
-stderr '^package rsc.io/qu...@v1.5.1: can only use path@version syntax with ''go get'' and ''go install'' in module-aware mode$'
+stderr '^package rsc.io/qu...@v1.5.1: can only use path@version syntax with ''go get'' and ''go install'' and ''go list -m ...'' in module-aware mode$'

env GO111MODULE=on
cd x
! go build rsc.io/qu...@v1.5.1
-stderr '^package rsc.io/qu...@v1.5.1: can only use path@version syntax with ''go get'' and ''go install'' in module-aware mode$'
+stderr '^package rsc.io/qu...@v1.5.1: can only use path@version syntax with ''go get'' and ''go install'' and ''go list -m ...'' in module-aware mode$'

-- x/go.mod --
module x

To view, visit change 381195. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Iefb0bd30f6dee3feef46fb9369b9941cc2de2263
Gerrit-Change-Number: 381195
Gerrit-PatchSet: 1
Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
Gerrit-MessageType: newchange

Ian Lance Taylor (Gerrit)

unread,
Jun 24, 2022, 4:00:04 PM6/24/22
to jiahua wang, goph...@pubsubhelper.golang.org, Bryan Mills, Michael Matloob, Russ Cox, Ian Lance Taylor, Gopher Robot, golang-co...@googlegroups.com

Attention is currently required from: Bryan Mills, Michael Matloob, jiahua wang.

View Change

1 comment:

  • Patchset:

To view, visit change 381195. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Iefb0bd30f6dee3feef46fb9369b9941cc2de2263
Gerrit-Change-Number: 381195
Gerrit-PatchSet: 1
Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
Gerrit-CC: Russ Cox <r...@golang.org>
Gerrit-Attention: Bryan Mills <bcm...@google.com>
Gerrit-Attention: jiahua wang <wjh1...@gmail.com>
Gerrit-Attention: Michael Matloob <mat...@golang.org>
Gerrit-Comment-Date: Fri, 24 Jun 2022 20:00:00 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

Bryan Mills (Gerrit)

unread,
Sep 9, 2022, 4:40:05 PM9/9/22
to jiahua wang, goph...@pubsubhelper.golang.org, Bryan Mills, Michael Matloob, Russ Cox, Ian Lance Taylor, Gopher Robot, golang-co...@googlegroups.com

Attention is currently required from: Michael Matloob, jiahua wang.

View Change

1 comment:

  • File src/cmd/go/internal/load/pkg.go:

    • Patch Set #2, Line 824: 'go get' and 'go install' and 'go list -m ...'

      This list of commands is getting pretty long, and even with this addition it is missing an entry for `go run`, from proposal #42088.

      I'm not sure what to do about that, but I don't think it makes sense to just keep expanding a list of commands that don't necessarily have anything to do with what the user intended to do.

To view, visit change 381195. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Iefb0bd30f6dee3feef46fb9369b9941cc2de2263
Gerrit-Change-Number: 381195
Gerrit-PatchSet: 2
Gerrit-Owner: jiahua wang <wjh1...@gmail.com>
Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
Gerrit-CC: Russ Cox <r...@golang.org>
Gerrit-Attention: jiahua wang <wjh1...@gmail.com>
Gerrit-Attention: Michael Matloob <mat...@golang.org>
Gerrit-Comment-Date: Fri, 09 Sep 2022 20:40:02 +0000
Reply all
Reply to author
Forward
0 new messages