Skip to content

Commit 0e95843

Browse files
committed
internal/mod/module: improve error message
We can distinguish between "not well formed" and "is not canonical". Following suggestion here: https://review.gerrithub.io/c/cue-lang/cue/+/1168707/comment/031030c7_0f2c5409 For #2330. Signed-off-by: Roger Peppe <[email protected]> Change-Id: I1dab05fc03cfcb856b54d1f5757372808a685049 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1168802 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Paul Jolly <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 3142030 commit 0e95843

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

internal/mod/module/module.go

+3
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ func MustNewVersion(path string, vers string) Version {
108108
// if the version isn't empty; if the version is empty, it's an error.
109109
func NewVersion(path string, vers string) (Version, error) {
110110
if vers != "" && vers != "none" {
111+
if !semver.IsValid(vers) {
112+
return Version{}, fmt.Errorf("version %q (of module %q) is not well formed", vers, path)
113+
}
111114
if semver.Canonical(vers) != vers {
112115
return Version{}, fmt.Errorf("version %q (of module %q) is not canonical", vers, path)
113116
}

internal/mod/module/module_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ var newVersionTests = []struct {
8383
path: "foo.com/bar",
8484
vers: "",
8585
wantError: `path "foo.com/bar" has no major version`,
86+
}, {
87+
path: "x.com",
88+
vers: "bad",
89+
wantError: `version "bad" \(of module "x.com"\) is not well formed`,
8690
}}
8791

8892
func TestNewVersion(t *testing.T) {

0 commit comments

Comments
 (0)