Skip to content

Commit 28a05f5

Browse files
ZekeLugopherbot
authored andcommitted
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: 410de1b GitHub-Pull-Request: #56050 Reviewed-on: https://go-review.googlesource.com/c/go/+/438147 Run-TryBot: hopehook <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent 4fe1971 commit 28a05f5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/cmd/go/internal/modload/init.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,11 @@ func LoadModFile(ctx context.Context) *Requirements {
718718
var fixed bool
719719
data, f, err := ReadModFile(gomod, fixVersion(ctx, &fixed))
720720
if err != nil {
721-
base.Fatalf("go: %v", err)
721+
if inWorkspaceMode() {
722+
base.Fatalf("go: cannot load module listed in go.work file: %v", err)
723+
} else {
724+
base.Fatalf("go: %v", err)
725+
}
722726
}
723727

724728
modFiles = append(modFiles, f)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
! go list .
2+
stderr '^go: cannot load module listed in go\.work file: open .+go\.mod:'
3+
4+
-- go.work --
5+
use ./y
6+
-- x/go.mod --
7+
module x
8+
9+
go 1.19
10+
-- x/m.go --
11+
package m

0 commit comments

Comments
 (0)