{"record":{"id":"90bb25b4329d5169","repo":"lima-vm/lima","slug":"failed-to-remove-q-w-90bb25","errorCode":null,"errorMessage":"failed to remove %#q: %w","messagePattern":"failed to remove %#q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/instance/delete.go","lineNumber":33,"sourceCode":")\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}\n\tserver.Stop(inst.Dir, true)\n\n\treturn nil\n}","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/instance/delete.go#L15-L51","documentation":"pkg/instance.Delete failed at the final step: os.RemoveAll(inst.Dir) could not delete the instance directory under ${LIMA_HOME}. The driver resources were already unregistered, so only filesystem cleanup failed. The message quotes the directory path and wraps the OS error.","triggerScenarios":"instance.Delete reaches os.RemoveAll(inst.Dir) after successful (or skipped) unregister, and RemoveAll fails — permission denied on files owned by another user/root, immutable files, or files still held open on Windows.","commonSituations":"LIMA_HOME inside a root-owned or synced/locked folder (Dropbox/OneDrive), running limactl as a different user than the one who created the VM, or a lingering process holding files open.","solutions":["Read the wrapped OS error to find the offending path; check ownership/permissions of ~/.lima/<instance>.","Stop lingering processes (hostagent/guestagent) and retry.","Delete manually with elevated permissions: `sudo rm -rf ~/.lima/<instance>` (only after confirming no VM is running).","Move LIMA_HOME off synced/locked filesystems for future instances."],"exampleFix":"// before (permission denied)\nrm -rf ~/.lima/myvm\n// after\nsudo rm -rf ~/.lima/myvm","handlingStrategy":"validation","validationCode":"dir := inst.Dir\nif info, err := os.Stat(dir); err == nil {\n    if err := unix.Access(dir, unix.W_OK); err != nil {\n        return fmt.Errorf(\"cannot remove %s: not writable\", dir)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := instance.Delete(ctx, inst, false); err != nil {\n    if strings.Contains(err.Error(), \"failed to remove\") {\n        // resources unregistered; safe to clean up manually with elevated perms\n        return os.RemoveAll(inst.Dir)\n    }\n    return err\n}","preventionTips":["Keep LIMA_HOME on a normal local filesystem owned by the running user","Avoid running limactl under sudo for some instances and not others","Stop host/guest processes before deleting on Windows (file locks)"],"tags":["instance-delete","filesystem-permission","cleanup"],"backgroundTag":"directory-removal-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}