Skip to content

Commit 0da58d0

Browse files
author
Jay Conrod
committed
cmd/go: clarify error text for module path mismatch
This error occurs when a module is loaded with one name (for example, github.com/golang/lint) but declares a different path in its go.mod (golang.org/x/lint). The current text "unexpected module path" is confusing. It doesn't explain why the path was unexpected, and it's not clear what was expected. With this change, the error text includes the module and version containing the go.mod file with the error, the declared module path, and the loaded module path. The paths are vertically aligned so differences are visually obvious. As with other module version errors, the shortest chain of requirements is printed. This change supercedes CL 158477. Fixes #28489 Change-Id: Ieb07d00bcae182376d7be6aad111c84fbf784354 Reviewed-on: https://go-review.googlesource.com/c/go/+/185985 Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent a6a7b14 commit 0da58d0

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/cmd/go/internal/modload/load.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,9 @@ func (r *mvsReqs) required(mod module.Version) ([]module.Version, error) {
11361136
return nil, module.VersionError(mod, errors.New("parsing go.mod: missing module line"))
11371137
}
11381138
if mpath := f.Module.Mod.Path; mpath != origPath && mpath != mod.Path {
1139-
return nil, module.VersionError(mod, fmt.Errorf("parsing go.mod: unexpected module path %q", mpath))
1139+
return nil, module.VersionError(mod, fmt.Errorf(`parsing go.mod:
1140+
module declares its path as: %s
1141+
but was loaded as: %s`, mod.Path, mpath))
11401142
}
11411143
if f.Go != nil {
11421144
r.versions.LoadOrStore(mod, f.Go.Version)

src/cmd/go/testdata/script/mod_load_badchain.txt

+15-5
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,29 @@ import (
5757
func Test(t *testing.T) {}
5858
-- update-main-expected --
5959
go get: example.com/badchain/[email protected] updating to
60-
example.com/badchain/[email protected]: parsing go.mod: unexpected module path "example.com/badchain/wrong"
60+
example.com/badchain/[email protected]: parsing go.mod:
61+
module declares its path as: example.com/badchain/c
62+
but was loaded as: example.com/badchain/wrong
6163
-- update-a-expected --
6264
go get: example.com/badchain/[email protected] requires
6365
example.com/badchain/[email protected] requires
64-
example.com/badchain/[email protected]: parsing go.mod: unexpected module path "example.com/badchain/wrong"
66+
example.com/badchain/[email protected]: parsing go.mod:
67+
module declares its path as: example.com/badchain/c
68+
but was loaded as: example.com/badchain/wrong
6569
-- list-expected --
6670
go: example.com/badchain/[email protected] requires
6771
example.com/badchain/[email protected] requires
68-
example.com/badchain/[email protected]: parsing go.mod: unexpected module path "example.com/badchain/wrong"
72+
example.com/badchain/[email protected]: parsing go.mod:
73+
module declares its path as: example.com/badchain/c
74+
but was loaded as: example.com/badchain/wrong
6975
-- list-missing-expected --
7076
go: m/use imports
71-
example.com/badchain/c: example.com/badchain/[email protected]: parsing go.mod: unexpected module path "example.com/badchain/wrong"
77+
example.com/badchain/c: example.com/badchain/[email protected]: parsing go.mod:
78+
module declares its path as: example.com/badchain/c
79+
but was loaded as: example.com/badchain/wrong
7280
-- list-missing-test-expected --
7381
go: m/testuse tested by
7482
m/testuse.test imports
75-
example.com/badchain/c: example.com/badchain/[email protected]: parsing go.mod: unexpected module path "example.com/badchain/wrong"
83+
example.com/badchain/c: example.com/badchain/[email protected]: parsing go.mod:
84+
module declares its path as: example.com/badchain/c
85+
but was loaded as: example.com/badchain/wrong

0 commit comments

Comments
 (0)