Quan Tong has uploaded this change for review.
cmd/go/internal/modload: if $GOPATH/go.mod exists, print its value
Fixes #46807
Change-Id: If9db4c0377f7c36af9c367398d3da494be04cd41
---
M src/cmd/go/internal/modload/init.go
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index b9d9d2e..3ddaeb4 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -485,7 +485,7 @@
if len(list) > 0 && list[0] != "" {
gopath = list[0]
if _, err := fsys.Stat(filepath.Join(gopath, "go.mod")); err == nil {
- base.Fatalf("$GOPATH/go.mod exists but should not")
+ base.Fatalf("%s/go.mod exists but should not", gopath)
}
}
}
To view, visit change 539596. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Michael Matloob, Quan Tong.
1 comment:
File src/cmd/go/internal/modload/init.go:
Patch Set #1, Line 488: base.Fatalf("%s/go.mod exists but should not", gopath)
I'm not sure how this relates to #46807. The problem there is that `go env` doesn't produce its usual output when this error is triggered.
(This failure mode was added in CL 108379 for #24106.)
Perhaps we should just ignore such a file (as we do for `/tmp/go.mod` as of CL 129063) instead of calling `base.Fatalf` for it?
To view, visit change 539596. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Michael Matloob, Quan Tong.
1 comment:
File src/cmd/go/internal/modload/init.go:
Patch Set #1, Line 488: base.Fatalf("%s/go.mod exists but should not", gopath)
I'm not sure how this relates to #46807. […]
FWIW (as the original reporter of #46807), printing the value of GOPATH would have made it much easier to figure out the motivating problem. Somehow the user's GOENV had changed to a non-default value and pointed their GOPATH to a non-default directory that contained a go.mod file. At that point, all go commands broke, including `go env`, so we couldn't figure out what directory the go tool was treating as $GOPATH in that error message; their default GOPATH was clean.
That said, I do agree this isn't quite the right change. If the same situation were to happen again, this message would guide the user to remove a go.mod that probably should exist. We want them to check their environment instead, particularly GOPATH and GOENV; it's just currently hard or impossible to do so. Making `go env` in particular ignore $GOPATH/go.mod feels like the ideal solution.
To view, visit change 539596. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Branden Brown, Bryan Mills, Michael Matloob.
1 comment:
File src/cmd/go/internal/modload/init.go:
Patch Set #1, Line 488: base.Fatalf("%s/go.mod exists but should not", gopath)
FWIW (as the original reporter of #46807), printing the value of GOPATH would have made it much easi […]
`modload.Init()` is called in multiple places:
I'm not sure how can we just make `go env` ignore `$GOPATH/go.mod` file.
To view, visit change 539596. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Branden Brown, Bryan Mills, Michael Matloob.
Quan Tong uploaded patch set #2 to this change.
cmd/go/internal/modload: ignore $GOPATH/go.mod
The existing implementation returns a fatal error if $GOPATH/go.mod exists.
We couldn't figure out what directory the go tool was treating as $GOPATH
in the error message.
Fixes #46807
Change-Id: If9db4c0377f7c36af9c367398d3da494be04cd41
---
M src/cmd/go/internal/modload/init.go
1 file changed, 7 insertions(+), 1 deletion(-)
To view, visit change 539596. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Branden Brown, Michael Matloob, Quan Tong.
1 comment:
Commit Message:
Patch Set #2, Line 13: Fixes #46807
Thanks! But before we can merge this fix, it needs a regression test — please add one in `src/cmd/go/testdata/script`.
(See the `README` file there for a description of the script environment, and note that the working directory at the start of each test script is a new `$GOPATH/src` directory.)
To view, visit change 539596. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Branden Brown, Michael Matloob, Quan Tong.
Quan Tong uploaded patch set #3 to this change.
cmd/go/internal/modload: ignore $GOPATH/go.mod
The existing implementation returns a fatal error if $GOPATH/go.mod exists.
We couldn't figure out what directory the go tool was treating as $GOPATH
in the error message.
Fixes #46807
Change-Id: If9db4c0377f7c36af9c367398d3da494be04cd41
---
M src/cmd/go/internal/modload/init.go
A src/cmd/go/testdata/script/env_issue46807.txt
2 files changed, 19 insertions(+), 1 deletion(-)
To view, visit change 539596. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Branden Brown, Bryan Mills, Michael Matloob.
1 comment:
Commit Message:
Patch Set #2, Line 13: Fixes #46807
Thanks! But before we can merge this fix, it needs a regression test — please add one in `src/cmd/go […]
Done
To view, visit change 539596. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Branden Brown, Michael Matloob, Quan Tong.
Patch set 3:Code-Review +2Commit-Queue +1
Attention is currently required from: Branden Brown, Michael Matloob, Quan Tong.
Patch set 3:Auto-Submit +1
Attention is currently required from: Branden Brown, Michael Matloob, Quan Tong.
Patch set 3:Code-Review +1
Gopher Robot submitted this change.
cmd/go/internal/modload: ignore $GOPATH/go.mod
The existing implementation returns a fatal error if $GOPATH/go.mod exists.
We couldn't figure out what directory the go tool was treating as $GOPATH
in the error message.
Fixes #46807
Change-Id: If9db4c0377f7c36af9c367398d3da494be04cd41
Reviewed-on: https://go-review.googlesource.com/c/go/+/539596
LUCI-TryBot-Result: Go LUCI <golang...@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Bryan Mills <bcm...@google.com>
Reviewed-by: Bryan Mills <bcm...@google.com>
Reviewed-by: Heschi Kreinick <hes...@google.com>
---
M src/cmd/go/internal/modload/init.go
A src/cmd/go/testdata/script/env_issue46807.txt
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index b9d9d2e..f4f4a68 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -485,7 +485,13 @@
if len(list) > 0 && list[0] != "" {
gopath = list[0]
if _, err := fsys.Stat(filepath.Join(gopath, "go.mod")); err == nil {
- base.Fatalf("$GOPATH/go.mod exists but should not")
+ fmt.Fprintf(os.Stderr, "go: warning: ignoring go.mod in $GOPATH %v\n", gopath)
+ if RootMode == NeedRoot {
+ base.Fatal(ErrNoModRoot)
+ }
+ if !mustUseModules {
+ return
+ }
}
}
}
diff --git a/src/cmd/go/testdata/script/env_issue46807.txt b/src/cmd/go/testdata/script/env_issue46807.txt
new file mode 100644
index 0000000..e37bc63
--- /dev/null
+++ b/src/cmd/go/testdata/script/env_issue46807.txt
@@ -0,0 +1,12 @@
+! go mod tidy
+stderr '^go: warning: ignoring go.mod in \$GOPATH'
+stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules'''
+
+go env
+stdout 'GOPATH='
+stderr '^go: warning: ignoring go.mod in \$GOPATH'
+
+-- $GOPATH/go.mod --
+module bug
+
+go 1.21
\ No newline at end of file
To view, visit change 539596. To unsubscribe, or for help writing mail filters, visit settings.