{"record":{"id":"b0a4b8f55aef1066","repo":"lima-vm/lima","slug":"failed-to-remove-s-w","errorCode":null,"errorMessage":"failed to remove %s: %w","messagePattern":"failed to remove (.+?): %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/autostart_darwin.go","lineNumber":154,"sourceCode":"\t\treturn fmt.Errorf(\"failed to enable LaunchDaemon: %w\", err)\n\t}\n\tif err := runSudo(ctx, \"launchctl\", \"bootstrap\", \"system\", destPath); err != nil {\n\t\treturn fmt.Errorf(\"failed to bootstrap LaunchDaemon: %w\", err)\n\t}\n\n\tlogrus.Infof(\"LaunchDaemon installed for instance %q (runs as %q at boot)\", instName, userName)\n\tlogrus.Infof(\"Plist: %s\", destPath)\n\treturn nil\n}\n\nfunc daemonUninstall(ctx context.Context, instName string) error {\n\tsvcTarget := \"system/\" + launchd.DaemonServiceNameFrom(instName)\n\tdestPath := launchd.GetDaemonPlistPath(instName)\n\n\t_ = runSudo(ctx, \"launchctl\", \"bootout\", svcTarget)\n\t_ = runSudo(ctx, \"launchctl\", \"disable\", svcTarget)\n\tif err := runSudo(ctx, \"rm\", \"-f\", destPath); err != nil {\n\t\treturn fmt.Errorf(\"failed to remove %s: %w\", destPath, err)\n\t}\n\tlogrus.Infof(\"LaunchDaemon uninstalled for instance %q\", instName)\n\treturn nil\n}\n\n// runSudo executes a command under sudo, inheriting the terminal so password prompts work.\nfunc runSudo(ctx context.Context, args ...string) error {\n\tcmd := exec.CommandContext(ctx, \"sudo\", args...) //nolint:gosec // args are constructed internally, not from user input\n\tcmd.Stdout = os.Stdout\n\tcmd.Stderr = os.Stderr\n\tcmd.Stdin = os.Stdin\n\tlogrus.Infof(\"running: sudo %v\", args)\n\treturn cmd.Run()\n}\n","sourceCodeStart":136,"sourceCodeEnd":169,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/autostart_darwin.go#L136-L169","documentation":"daemonUninstall removes the LaunchDaemon plist with `sudo rm -f <dest>` after booting out and disabling the service; this error wraps that rm failure. Since rm -f rarely fails on a missing file, this usually means sudo was denied or the file is protected.","triggerScenarios":"`limactl autostart --uninstall <instance>` (autostartDisableAction) on macOS when a boot-mode daemon exists at /Library/LaunchDaemons/io.lima-vm.daemon.<instance>.plist and `sudo rm -f` exits nonzero: canceled password prompt, non-admin user, or MDM/SIP protection on the path.","commonSituations":"Running disable from a script without a TTY so sudo cannot prompt for a password; managed Macs where LaunchDaemons writes are policy-blocked; stale plist owned by root with restrictive permissions and sudo refused.","solutions":["Rerun interactively and enter the sudo password","Verify sudo rights: `sudo -v`","Remove manually if policy allows: `sudo rm -f /Library/LaunchDaemons/io.lima-vm.daemon.<instance>.plist`","Check MDM/security-agent restrictions on /Library/LaunchDaemons"],"exampleFix":"// before: limactl autostart --uninstall myinstance  (sudo: no tty)\n// after:  sudo -v && limactl autostart --uninstall myinstance","handlingStrategy":"try-catch","validationCode":"sudo -v 2>/dev/null || { echo \"sudo unavailable\"; exit 1; }\nls -l /Library/LaunchDaemons/io.lima-vm.daemon.<instance>.plist 2>/dev/null","typeGuard":null,"tryCatchPattern":"if err := daemonUninstall(ctx, inst.Name); err != nil {\n\tif strings.Contains(err.Error(), \"failed to remove\") {\n\t\tlogrus.Warn(\"Plist removal failed; remove manually: sudo rm -f /Library/LaunchDaemons/io.lima-vm.daemon.<instance>.plist\")\n\t\treturn\n\t}\n\tpanic(err)\n}","preventionTips":["Run disable commands interactively so sudo can prompt","Cache credentials with `sudo -v` in scripted cleanups","Ensure MDM permits modification of /Library/LaunchDaemons","Disable autostart before deleting the instance"],"tags":["macos","launchd","sudo","permissions"],"backgroundTag":"sudo-permission-denied","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}