Gerrit Bot has uploaded this change for review.
cmd/go/internal/modload: improve error message for failing to read module listed in go.work
Run "go build ./x" in this workspace:
-- go.work --
use ./y
-- x/go.mod --
module x
go 1.19
-- x/m.go --
package m
It fails with: "go: open /tmp/foo/y/go.mod: no such file or directory".
It's unclear where the name "y" comes from.
This change will emit error like: "go: cannot load module y named in
go.work file: open /tmp/foo/y/go.mod: no such file or directory"
It would be better to add the content of the use line to the error.
But we don't have that info when the error happens. So we just use the
base name of the module directory as the module name.
Fixes #55952.
Change-Id: Ia45dd915e3fbd6e33340f352b3d6235c6c31190b
GitHub-Last-Rev: 51236225618acef05b1b351891cb2e17db292d71
GitHub-Pull-Request: golang/go#56050
---
M src/cmd/go/internal/modload/init.go
A src/cmd/go/testdata/script/work_use_issue55952.txt
2 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index 7da2beb..260bc23 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -718,7 +718,11 @@
var fixed bool
data, f, err := ReadModFile(gomod, fixVersion(ctx, &fixed))
if err != nil {
- base.Fatalf("go: %v", err)
+ if inWorkspaceMode() {
+ base.Fatalf("go: cannot load module %s named in go.work file: %v", filepath.Base(modroot), err)
+ } else {
+ base.Fatalf("go: %v", err)
+ }
}
modFiles = append(modFiles, f)
diff --git a/src/cmd/go/testdata/script/work_use_issue55952.txt b/src/cmd/go/testdata/script/work_use_issue55952.txt
new file mode 100644
index 0000000..9d7bd0f
--- /dev/null
+++ b/src/cmd/go/testdata/script/work_use_issue55952.txt
@@ -0,0 +1,11 @@
+! go list .
+stderr '^go: cannot load module y named in go\.work file: open .+go\.mod: no such file or directory$'
+
+-- go.work --
+use ./y
+-- x/go.mod --
+module x
+
+go 1.19
+-- x/m.go --
+package m
To view, visit change 438147. To unsubscribe, or for help writing mail filters, visit settings.
Gerrit Bot uploaded patch set #2 to this change.
cmd/go/internal/modload: improve error message for failing to read module listed in go.work
Run "go build ./x" in this workspace:
-- go.work --
use ./y
-- x/go.mod --
module x
go 1.19
-- x/m.go --
package m
It fails with: "go: open /tmp/foo/y/go.mod: no such file or directory".
It's unclear where the name "y" comes from.
This CL makes it emit error like: "go: cannot load module y named in
go.work file: open /tmp/foo/y/go.mod: no such file or directory"
It would be better to add the content of the use line to the error.
But we don't have that info when the error happens. So we just use the
base name of the module directory as the module name.
Fixes #55952.
Change-Id: Ia45dd915e3fbd6e33340f352b3d6235c6c31190b
GitHub-Last-Rev: 51236225618acef05b1b351891cb2e17db292d71
GitHub-Pull-Request: golang/go#56050
---
M src/cmd/go/internal/modload/init.go
A src/cmd/go/testdata/script/work_use_issue55952.txt
2 files changed, 49 insertions(+), 1 deletion(-)
To view, visit change 438147. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Michael Matloob.
Patch set 2:Code-Review +2
1 comment:
Patchset:
Thanks for the fix, Zeke.
To view, visit change 438147. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Michael Matloob.
1 comment:
File src/cmd/go/internal/modload/init.go:
Patch Set #2, Line 722: filepath.Base(modroot)
I don't think the call to `filepath.Base` is appropriate here — what if my `go.work` file has a bunch of modules that all end with the same element?
```
use (
./x/foo
./y/foo
./z/foo
)
```
Plus, usually when we use the word "module" we follow it with a module path, but nothing requires that the final element of the directory path has anything to do with the module path contained in that directory. 😅
To view, visit change 438147. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Michael Matloob.
1 comment:
File src/cmd/go/internal/modload/init.go:
Patch Set #2, Line 722: filepath.Base(modroot)
I don't think the call to `filepath.Base` is appropriate here — what if my `go. […]
Understood. How about removing this information from the message? Like this:
```
base.Fatalf("go: cannot load module added to go.work file: %v", err)
```
We can try to get the content of the `use` line here. But it could make the code complicated and it seems that it does not worth it.
To view, visit change 438147. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Michael Matloob, Zeke Lu.
1 comment:
File src/cmd/go/internal/modload/init.go:
Patch Set #2, Line 722: filepath.Base(modroot)
Understood. How about removing this information from the message? Like this: […]
That sounds good. Thanks!
To view, visit change 438147. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Michael Matloob, Zeke Lu.
Gerrit Bot uploaded patch set #3 to this change.
cmd/go/internal/modload: improve error message for failing to read module listed in go.work
Run "go build ./x" in this workspace:
-- go.work --
use ./y
-- x/go.mod --
module x
go 1.19
-- x/m.go --
package m
It fails with: "go: open /tmp/foo/y/go.mod: no such file or directory".
It's unclear where the name "y" comes from.
This change will emit error like: "go: cannot load module added to
go.work file: open /tmp/foo/y/go.mod: no such file or directory"
Fixes #55952.
Change-Id: Ia45dd915e3fbd6e33340f352b3d6235c6c31190b
GitHub-Last-Rev: abd77415d8028df94d5f68254f028c7fb1b5066e
GitHub-Pull-Request: golang/go#56050
---
M src/cmd/go/internal/modload/init.go
A src/cmd/go/testdata/script/work_use_issue55952.txt
2 files changed, 45 insertions(+), 1 deletion(-)
To view, visit change 438147. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Michael Matloob.
1 comment:
File src/cmd/go/internal/modload/init.go:
Patch Set #2, Line 722: filepath.Base(modroot)
That sounds good. […]
Done!
Thank you Alan for the idea! And thank you Bryan for your review! ❤️
To view, visit change 438147. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Michael Matloob.
Patch set 3:Code-Review +2
1 comment:
File src/cmd/go/internal/modload/init.go:
Patch Set #3, Line 722: added to
(nit) s/added to/listed in/
(since this invocation of the `go` command is not the one adding it)
To view, visit change 438147. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Michael Matloob.
Gerrit Bot uploaded patch set #4 to this change.
cmd/go/internal/modload: improve error message for failing to read module listed in go.work
Run "go build ./x" in this workspace:
-- go.work --
use ./y
-- x/go.mod --
module x
go 1.19
-- x/m.go --
package m
It fails with: "go: open /tmp/foo/y/go.mod: no such file or directory".
It's unclear where the name "y" comes from.
This change will emit error like: "go: cannot load module listed in
go.work file: open /tmp/foo/y/go.mod: no such file or directory"
Fixes #55952.
Change-Id: Ia45dd915e3fbd6e33340f352b3d6235c6c31190b
GitHub-Last-Rev: ec97646f2242297621dc6e4654a500fa5cf9be10
GitHub-Pull-Request: golang/go#56050
---
M src/cmd/go/internal/modload/init.go
A src/cmd/go/testdata/script/work_use_issue55952.txt
2 files changed, 45 insertions(+), 1 deletion(-)
To view, visit change 438147. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Michael Matloob.
1 comment:
File src/cmd/go/internal/modload/init.go:
Patch Set #3, Line 722: added to
(nit) s/added to/listed in/ […]
Done
To view, visit change 438147. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Michael Matloob.
Patch set 4:Run-TryBot +1Auto-Submit +1Code-Review +2
Attention is currently required from: Bryan Mills, Michael Matloob.
Gerrit Bot uploaded patch set #5 to this change.
The following approvals got outdated and were removed: Auto-Submit+1 by Bryan Mills, Run-TryBot+1 by Bryan Mills, TryBot-Result-1 by Gopher Robot
cmd/go/internal/modload: improve error message for failing to read module listed in go.work
Run "go build ./x" in this workspace:
-- go.work --
use ./y
-- x/go.mod --
module x
go 1.19
-- x/m.go --
package m
It fails with: "go: open /tmp/foo/y/go.mod: no such file or directory".
It's unclear where the name "y" comes from.
This change will emit error like: "go: cannot load module listed in
go.work file: open /tmp/foo/y/go.mod: no such file or directory"
Fixes #55952.
Change-Id: Ia45dd915e3fbd6e33340f352b3d6235c6c31190b
GitHub-Last-Rev: 410de1b4a71d07bbd5abd1482b6d55fa29f31336
GitHub-Pull-Request: golang/go#56050
---
M src/cmd/go/internal/modload/init.go
A src/cmd/go/testdata/script/work_use_issue55952.txt
2 files changed, 45 insertions(+), 1 deletion(-)
To view, visit change 438147. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Michael Matloob.
1 comment:
Patchset:
3 of 29 TryBots failed. […]
Fixed.
To view, visit change 438147. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Bryan Mills, Michael Matloob.
Patch set 5:Run-TryBot +1
Attention is currently required from: Michael Matloob.
Patch set 5:Run-TryBot +1Auto-Submit +1Code-Review +2
Attention is currently required from: Michael Matloob, Zeke Lu.
1 comment:
Patchset:
Fixed.
Hi @lvz...@gmail.com. If you are ready to submit this CL, I think you should mark it as resolved.
So this CL will be committed automatically.
To view, visit change 438147. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Michael Matloob, hopehook.
1 comment:
Patchset:
Hi @lvz...@gmail.com. If you are ready to submit this CL, I think you should mark it as resolved. […]
I thought I have marked it as resolved. Obviously I haven't. Thank you! I'm going to do it.
To view, visit change 438147. To unsubscribe, or for help writing mail filters, visit settings.
Gopher Robot submitted this change.
cmd/go/internal/modload: improve error message for failing to read module listed in go.work
Run "go build ./x" in this workspace:
-- go.work --
use ./y
-- x/go.mod --
module x
go 1.19
-- x/m.go --
package m
It fails with: "go: open /tmp/foo/y/go.mod: no such file or directory".
It's unclear where the name "y" comes from.
This change will emit error like: "go: cannot load module listed in
go.work file: open /tmp/foo/y/go.mod: no such file or directory"
Fixes #55952.
Change-Id: Ia45dd915e3fbd6e33340f352b3d6235c6c31190b
GitHub-Last-Rev: 410de1b4a71d07bbd5abd1482b6d55fa29f31336
GitHub-Pull-Request: golang/go#56050
Reviewed-on: https://go-review.googlesource.com/c/go/+/438147
Run-TryBot: hopehook <hope...@golangcn.org>
TryBot-Result: Gopher Robot <go...@golang.org>
Auto-Submit: Bryan Mills <bcm...@google.com>
Reviewed-by: Bryan Mills <bcm...@google.com>
Run-TryBot: Bryan Mills <bcm...@google.com>
Reviewed-by: Alan Donovan <adon...@google.com>
---
M src/cmd/go/internal/modload/init.go
A src/cmd/go/testdata/script/work_use_issue55952.txt
2 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index 7da2beb..06be184 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -718,7 +718,11 @@
var fixed bool
data, f, err := ReadModFile(gomod, fixVersion(ctx, &fixed))
if err != nil {
- base.Fatalf("go: %v", err)
+ if inWorkspaceMode() {
+ base.Fatalf("go: cannot load module listed in go.work file: %v", err)
+ } else {
+ base.Fatalf("go: %v", err)
+ }
}
modFiles = append(modFiles, f)
diff --git a/src/cmd/go/testdata/script/work_use_issue55952.txt b/src/cmd/go/testdata/script/work_use_issue55952.txt
new file mode 100644
index 0000000..2eef361
--- /dev/null
+++ b/src/cmd/go/testdata/script/work_use_issue55952.txt
@@ -0,0 +1,11 @@
+! go list .
+stderr '^go: cannot load module listed in go\.work file: open .+go\.mod:'
+
+-- go.work --
+use ./y
+-- x/go.mod --
+module x
+
+go 1.19
+-- x/m.go --
+package m
To view, visit change 438147. To unsubscribe, or for help writing mail filters, visit settings.