{"record":{"id":"d54461f45f6b5180","repo":"lima-vm/lima","slug":"failed-to-unregister-q-w","errorCode":null,"errorMessage":"failed to unregister %#q: %w","messagePattern":"failed to unregister %#q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/instance/delete.go","lineNumber":29,"sourceCode":"\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)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create driver instance: %w\", err)\n\t}\n\n\tif err := limaDriver.Delete(ctx); err != nil {\n\t\treturn fmt.Errorf(\"failed to delete driver instance: %w\", err)\n\t}","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/instance/delete.go#L11-L47","documentation":"During pkg/instance.Delete, the unregister step (which tears down driver resources and stops the hostagent socket server) failed. Lima wraps it with the instance directory path. Note unregister is only attempted when inst.Errors is empty; the delete of the instance directory is aborted so the instance remains registered.","triggerScenarios":"instance.Delete on a healthy instance (len(inst.Errors)==0) where unregister(ctx, inst) returns an error — e.g. CreateConfiguredDriver fails (see 648) or limaDriver.Delete fails (see 649).","commonSituations":"Driver resources (disk, ssh keys, network) cannot be cleaned because the driver config in the instance dir no longer matches the host, or the external driver process cannot be reached.","solutions":["Inspect the wrapped cause: 'failed to create driver instance' vs 'failed to delete driver instance'.","Retry after fixing the driver issue; if cleanup already partially ran, use --force or remove the instance dir manually.","As a last resort, manually `rm -rf ~/.lima/<instance>` after stopping the hostagent (`limactl stop -f`).","Keep lima.yaml in the instance dir intact so CreateConfiguredDriver can reconstruct the driver."],"exampleFix":"// before\nlimactl delete myvm\n// after\nlimactl stop -f myvm && limactl delete myvm","handlingStrategy":"try-catch","validationCode":"inst, _ := store.Inspect(ctx, instName)\nif len(inst.Errors) > 0 {\n    // unregister will be skipped; expect leftover driver resources\n    _ = inst\n}","typeGuard":null,"tryCatchPattern":"if err := instance.Delete(ctx, inst, false); err != nil {\n    if strings.Contains(err.Error(), \"failed to unregister\") {\n        // inspect wrapped cause (create-driver vs delete-driver) and retry once\n        return instance.Delete(ctx, inst, true)\n    }\n    return err\n}","preventionTips":["Keep the instance dir's lima.yaml intact until after successful delete","Don't mutate driver-related fields between create and delete","Retry delete once before manual cleanup"],"tags":["instance-delete","unregister","driver"],"backgroundTag":"instance-unregister-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}