{"record":{"id":"edb2be6525409b47","repo":"lima-vm/lima","slug":"failed-to-delete-instance-q-w","errorCode":null,"errorMessage":"failed to delete instance %#q: %w","messagePattern":"failed to delete instance %#q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/delete.go","lineNumber":55,"sourceCode":"\tctx := cmd.Context()\n\tforce, err := cmd.Flags().GetBool(\"force\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tvar errs []error\n\tfor _, instName := range args {\n\t\tinst, err := store.Inspect(ctx, instName)\n\t\tif err != nil {\n\t\t\tif errors.Is(err, os.ErrNotExist) {\n\t\t\t\tif err := warnAboutMissingInstance(instName); err != nil {\n\t\t\t\t\terrs = append(errs, err)\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\treturn err\n\t\t}\n\t\tif err := instance.Delete(ctx, inst, force); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to delete instance %#q: %w\", instName, err)\n\t\t}\n\t\tif registered, err := autostart.IsRegistered(ctx, inst); err != nil && !errors.Is(err, autostart.ErrNotSupported) {\n\t\t\tlogrus.WithError(err).Warnf(\"Failed to check if the autostart entry for instance %#q is registered\", instName)\n\t\t} else if registered {\n\t\t\tif err := autostart.UnregisterFromStartAtLogin(ctx, inst); err != nil {\n\t\t\t\tlogrus.WithError(err).Warnf(\"Failed to unregister the autostart entry for instance %#q\", instName)\n\t\t\t} else {\n\t\t\t\tlogrus.Infof(\"The autostart entry for instance %#q has been unregistered\", instName)\n\t\t\t}\n\t\t}\n\t\tlogrus.Infof(\"Deleted %#q (%#q)\", instName, inst.Dir)\n\t}\n\tif err := reconcile.Reconcile(ctx, \"\"); err != nil {\n\t\terrs = append(errs, err)\n\t}\n\treturn errors.Join(errs...)\n}\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/delete.go#L37-L73","documentation":"`limactl delete` failed while removing the instance via instance.Delete (which stops the VM if needed, unmounts, and removes the instance directory). The per-instance store error is wrapped with the instance name. Any sub-step — stopping the hostagent/guestagent, removing mounts, deleting the directory — can be the root cause surfaced in %w.","triggerScenarios":"`limactl delete <inst>` where instance.Delete errors: VM still running and force not passed, files inside the instance dir held open/locked, permission problems on ${LIMA_HOME}/instances/<name>, or partially corrupted instance state.","commonSituations":"Deleting a running instance without --force; another limactl process concurrently using the instance; NFS/network home directories with stale locks; root-created instances later managed by an unprivileged user.","solutions":["Stop the instance first: `limactl stop <inst>`, then delete again","Use `limactl delete --force <inst>` to skip graceful stop","Check for lingering lima processes (hostagent/qemu/vz) holding files in the instance dir and kill them","Fix permissions on ~/.lima/instances/<inst> (chown back to the current user)","If only the directory remains and lima.yaml is unreadable, remove the directory manually per the missing-instance guidance"],"exampleFix":"// before\n$ limactl delete myvm\n// failed to delete instance \"myvm\": instance is running\n// after\n$ limactl stop myvm && limactl delete myvm\n// or\n$ limactl delete --force myvm","handlingStrategy":"validation","validationCode":"const inst = await inspectInstance(name)\nif (inst.status === 'Running' && !force) {\n  await stopInstance(name)\n}","typeGuard":"function isRunning(inst: {status?: string}): boolean {\n  return inst?.status === 'Running'\n}","tryCatchPattern":"try {\n  await deleteInstance(name)\n} catch (err) {\n  if (/running|in use/i.test(err.message)) {\n    await deleteInstance(name, { force: true })\n  } else throw err\n}","preventionTips":["Always `limactl stop` before delete in automation","Check no other limactl processes hold the instance","Avoid running limactl as root on instances created as a normal user","Use --force only when the instance is known disposable"],"tags":["instance","delete","limactl"],"backgroundTag":"instance-delete-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}