@@ -118,13 +118,13 @@ func editAction(cmd *cobra.Command, args []string) error {
118
118
return err
119
119
}
120
120
if err := limayaml .Validate (y , true ); err != nil {
121
- rejectedYAML := "lima.REJECTED.yaml"
122
- if writeErr := os .WriteFile (rejectedYAML , yBytes , 0o644 ); writeErr != nil {
123
- return fmt .Errorf ("the YAML is invalid, attempted to save the buffer as %q but failed: %w: %w" , rejectedYAML , writeErr , err )
124
- }
125
- // TODO: may need to support editing the rejected YAML
126
- return fmt .Errorf ("the YAML is invalid, saved the buffer as %q: %w" , rejectedYAML , err )
121
+ return saveRejectedYAML (yBytes , err )
122
+ }
123
+
124
+ if err := limayaml .ValidateYAMLAgainstLatestConfig (yBytes , yContent ); err != nil {
125
+ return saveRejectedYAML (yBytes , err )
127
126
}
127
+
128
128
if err := os .WriteFile (filePath , yBytes , 0o644 ); err != nil {
129
129
return err
130
130
}
@@ -171,3 +171,13 @@ func askWhetherToStart() (bool, error) {
171
171
func editBashComplete (cmd * cobra.Command , _ []string , _ string ) ([]string , cobra.ShellCompDirective ) {
172
172
return bashCompleteInstanceNames (cmd )
173
173
}
174
+
175
+ // saveRejectedYAML writes the rejected config and returns an error.
176
+ func saveRejectedYAML (y []byte , origErr error ) error {
177
+ rejectedYAML := "lima.REJECTED.yaml"
178
+ if writeErr := os .WriteFile (rejectedYAML , y , 0o644 ); writeErr != nil {
179
+ return fmt .Errorf ("the YAML is invalid, attempted to save the buffer as %q but failed: %w: %w" , rejectedYAML , writeErr , origErr )
180
+ }
181
+ // TODO: may need to support editing the rejected YAML
182
+ return fmt .Errorf ("the YAML is invalid, saved the buffer as %q: %w" , rejectedYAML , origErr )
183
+ }
0 commit comments