{"record":{"id":"98f3e1e5fcbe64f1","repo":"lima-vm/lima","slug":"expected-status-q-got-q","errorCode":null,"errorMessage":"expected status %#q, got %#q","messagePattern":"expected status %#q, got %#q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/instance/delete.go","lineNumber":22,"sourceCode":"package instance\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/lima-vm/lima/v2/pkg/driver/external/server\"\n\t\"github.com/lima-vm/lima/v2/pkg/driverutil\"\n\t\"github.com/lima-vm/lima/v2/pkg/limatype\"\n)\n\nfunc Delete(ctx context.Context, inst *limatype.Instance, force bool) error {\n\tif inst.Protected {\n\t\treturn errors.New(\"instance is protected to prohibit accidental removal (Hint: use `limactl unprotect`)\")\n\t}\n\tif !force && inst.Status != limatype.StatusStopped {\n\t\treturn fmt.Errorf(\"expected status %#q, got %#q\", limatype.StatusStopped, inst.Status)\n\t}\n\n\tStopForcibly(inst)\n\n\tif len(inst.Errors) == 0 {\n\t\tif err := unregister(ctx, inst); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to unregister %#q: %w\", inst.Dir, err)\n\t\t}\n\t}\n\tif err := os.RemoveAll(inst.Dir); err != nil {\n\t\treturn fmt.Errorf(\"failed to remove %#q: %w\", inst.Dir, err)\n\t}\n\n\treturn nil\n}\n\nfunc unregister(ctx context.Context, inst *limatype.Instance) error {\n\tlimaDriver, err := driverutil.CreateConfiguredDriver(ctx, inst, 0)","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/instance/delete.go#L4-L40","documentation":"pkg/instance.Delete only removes instances whose status is StatusStopped unless force=true. This error reports the mismatch, quoting the expected and actual status via %#q (e.g. \"Running\"). It prevents deleting a live VM whose guestagent is still running.","triggerScenarios":"instance.Delete(ctx, inst, false) where inst.Status != limatype.StatusStopped — typically the instance is Running, and inst.Protected is false.","commonSituations":"Deleting a VM that is still booted or starting; stale status in lima.yaml after a crashed hostagent; a scheduler deleting instances without stopping them first.","solutions":["Stop the instance first: `limactl stop <instance>`, then delete.","Pass force=true (`limactl delete --force <instance>`) to delete regardless of status.","If the status is stale (VM is actually dead), refresh with `limactl list` or force-delete."],"exampleFix":"// before\nlimactl delete myvm\n// after\nlimactl stop myvm && limactl delete myvm","handlingStrategy":"validation","validationCode":"inst, _ := store.Inspect(ctx, instName)\nif inst.Status != limatype.StatusStopped {\n    if err := instance.StopForciblyWait(ctx, inst); err != nil {\n        return err\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := instance.Delete(ctx, inst, false); err != nil {\n    if strings.Contains(err.Error(), \"expected status\") {\n        // stop first, then retry\n        return instance.Delete(ctx, inst, true)\n    }\n    return err\n}","preventionTips":["Always stop instances before scripted deletes","Use `limactl list` to confirm status is Stopped","Treat stale statuses after crashes as force-delete candidates"],"tags":["instance-delete","instance-status","lifecycle"],"backgroundTag":"instance-not-stopped","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}