Skip to content

Commit 495db7a

Browse files
authored
Merge pull request #2501 from norio-nomura/validate-libyaml-before-overwriting
limactl start: fix the issue where using `--set` would overwrite the existing instance's `lima.yaml` without validation.
2 parents db7f60f + 5d3e51e commit 495db7a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

cmd/limactl/start.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,18 @@ func applyYQExpressionToExistingInstance(inst *store.Instance, yq string) (*stor
294294
if err != nil {
295295
return nil, err
296296
}
297+
y, err := limayaml.Load(yBytes, filePath)
298+
if err != nil {
299+
return nil, err
300+
}
301+
if err := limayaml.Validate(y, true); err != nil {
302+
rejectedYAML := "lima.REJECTED.yaml"
303+
if writeErr := os.WriteFile(rejectedYAML, yBytes, 0o644); writeErr != nil {
304+
return nil, fmt.Errorf("the YAML is invalid, attempted to save the buffer as %q but failed: %w: %w", rejectedYAML, writeErr, err)
305+
}
306+
// TODO: may need to support editing the rejected YAML
307+
return nil, fmt.Errorf("the YAML is invalid, saved the buffer as %q: %w", rejectedYAML, err)
308+
}
297309
if err := os.WriteFile(filePath, yBytes, 0o644); err != nil {
298310
return nil, err
299311
}

0 commit comments

Comments
 (0)