Skip to content

Commit 83337b5

Browse files
authored
Merge pull request #3286 from jandubois/robust-delete
Don't panic when deleting instances that don't validate
2 parents d7bf211 + 8e14243 commit 83337b5

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

pkg/instance/delete.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ func Delete(ctx context.Context, inst *store.Instance, force bool) error {
2121

2222
StopForcibly(inst)
2323

24-
if err := unregister(ctx, inst); err != nil {
25-
return fmt.Errorf("failed to unregister %q: %w", inst.Dir, err)
24+
if len(inst.Errors) == 0 {
25+
if err := unregister(ctx, inst); err != nil {
26+
return fmt.Errorf("failed to unregister %q: %w", inst.Dir, err)
27+
}
2628
}
27-
2829
if err := os.RemoveAll(inst.Dir); err != nil {
2930
return fmt.Errorf("failed to remove %q: %w", inst.Dir, err)
3031
}

pkg/limayaml/marshal.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@ func unmarshalDisk(dst *Disk, b []byte) error {
3535
return yaml.Unmarshal(b, dst)
3636
}
3737

38-
func Unmarshal(data []byte, v any, comment string) error {
39-
if err := yaml.UnmarshalWithOptions(data, v, yaml.CustomUnmarshaler[Disk](unmarshalDisk)); err != nil {
38+
func Unmarshal(data []byte, y *LimaYAML, comment string) error {
39+
if err := yaml.UnmarshalWithOptions(data, y, yaml.CustomUnmarshaler[Disk](unmarshalDisk)); err != nil {
4040
return fmt.Errorf("failed to unmarshal YAML (%s): %w", comment, err)
4141
}
4242
// the go-yaml library doesn't catch all markup errors, unfortunately
4343
// make sure to get a "second opinion", using the same library as "yq"
4444
if err := yqutil.ValidateContent(data); err != nil {
4545
return fmt.Errorf("failed to unmarshal YAML (%s): %w", comment, err)
4646
}
47-
if err := yaml.UnmarshalWithOptions(data, v, yaml.Strict(), yaml.CustomUnmarshaler[Disk](unmarshalDisk)); err != nil {
47+
var ignore LimaYAML
48+
if err := yaml.UnmarshalWithOptions(data, &ignore, yaml.Strict(), yaml.CustomUnmarshaler[Disk](unmarshalDisk)); err != nil {
4849
logrus.WithField("comment", comment).WithError(err).Warn("Non-strict YAML detected; please check for typos")
4950
}
5051
return nil

0 commit comments

Comments
 (0)