mirror of
https://github.com/golang/go
synced 2024-11-17 18:54:42 -07:00
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: 410de1b4a7
GitHub-Pull-Request: golang/go#56050
Reviewed-on: https://go-review.googlesource.com/c/go/+/438147
Run-TryBot: hopehook <hopehook@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
4fe1971b2d
commit
28a05f541d
@ -718,8 +718,12 @@ func LoadModFile(ctx context.Context) *Requirements {
|
||||
var fixed bool
|
||||
data, f, err := ReadModFile(gomod, fixVersion(ctx, &fixed))
|
||||
if err != nil {
|
||||
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)
|
||||
mainModule := f.Module.Mod
|
||||
|
11
src/cmd/go/testdata/script/work_use_issue55952.txt
vendored
Normal file
11
src/cmd/go/testdata/script/work_use_issue55952.txt
vendored
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user