Skip to content

Commit 134232b

Browse files
committed
fix limactl run bug by treating unparseable versions as latest instead of crashing during template validation.
Signed-off-by: olalekan odukoya <[email protected]>
1 parent 93ef4ce commit 134232b

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

pkg/limayaml/validate.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ func Validate(y *LimaYAML, warn bool) error {
4040
if _, err := versionutil.Parse(*y.MinimumLimaVersion); err != nil {
4141
errs = errors.Join(errs, fmt.Errorf("field `minimumLimaVersion` must be a semvar value, got %q: %w", *y.MinimumLimaVersion, err))
4242
}
43-
limaVersion, err := versionutil.Parse(version.Version)
44-
if err != nil {
45-
errs = errors.Join(errs, fmt.Errorf("can't parse builtin Lima version %q: %w", version.Version, err))
46-
}
47-
if limaVersion != nil && versionutil.GreaterThan(*y.MinimumLimaVersion, limaVersion.String()) {
48-
errs = errors.Join(errs, fmt.Errorf("template requires Lima version %q; this is only %q", *y.MinimumLimaVersion, limaVersion.String()))
43+
// Unparsable versions (like commit hashes or "<unknown>") are treated as "latest/greatest"
44+
// and will pass all version comparisons, allowing development builds to work.
45+
if !versionutil.GreaterEqual(version.Version, *y.MinimumLimaVersion) {
46+
errs = errors.Join(errs, fmt.Errorf("template requires Lima version %q; this is only %q", *y.MinimumLimaVersion, version.Version))
4947
}
5048
}
5149
if y.VMOpts.QEMU.MinimumVersion != nil {

pkg/limayaml/validate_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ func TestValidateMinimumLimaVersion(t *testing.T) {
3838
name: "minimumLimaVersion greater than current version",
3939
currentVersion: "1.1.1-114-g5bf5e513",
4040
minimumLimaVersion: "1.1.2",
41-
wantErr: `template requires Lima version "1.1.2"; this is only "1.1.1"`,
41+
wantErr: `template requires Lima version "1.1.2"; this is only "1.1.1-114-g5bf5e513"`,
4242
},
4343
{
4444
name: "invalid current version",
4545
currentVersion: "<unknown>",
4646
minimumLimaVersion: "0.8.0",
47-
wantErr: `can't parse builtin Lima version "<unknown>": <unknown> is not in dotted-tri format`,
47+
wantErr: "", // Now passes - unparseable versions are treated as "latest"
4848
},
4949
{
5050
name: "invalid minimumLimaVersion",
5151
currentVersion: "1.1.1-114-g5bf5e513",
5252
minimumLimaVersion: "invalid",
53-
wantErr: "field `minimumLimaVersion` must be a semvar value, got \"invalid\": invalid is not in dotted-tri format\ntemplate requires Lima version \"invalid\"; this is only \"1.1.1\"",
53+
wantErr: "field `minimumLimaVersion` must be a semvar value, got \"invalid\": invalid is not in dotted-tri format", // Only parse error, no comparison error
5454
},
5555
}
5656

pkg/version/versionutil/versionutil.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ func compare(limaVersion, oldVersion string) int {
3131
if err != nil {
3232
return 1
3333
}
34-
cmp := version.Compare(*semver.New(oldVersion))
34+
// Handle Unparsable oldVersion gracefully - treat as 0.0.0 so Unparsable limaVersion is always greater
35+
oldVer, err := semver.NewVersion(oldVersion)
36+
if err != nil {
37+
return 1
38+
}
39+
cmp := version.Compare(*oldVer)
3540
if cmp == 0 && strings.Contains(limaVersion, "-") {
3641
cmp = 1
3742
}

0 commit comments

Comments
 (0)