Make launchctl service removal sudo failures non-fatal #20803
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, Homebrew attempts to remove launchctl services during cask uninstallation, which requires root privileges. When running with
sudo, if thelaunchctl removecommand fails, it causes a fatal error that stops the uninstall process. This is problematic for users who:This PR changes the behavior to make launchctl service removal failures non-fatal, allowing the uninstall process to continue gracefully even when these operations fail.
Changes
Core Logic (
Library/Homebrew/cask/artifact/abstract_uninstall.rb)launchctl removecommand: Changed frommust_succeed: sudotomust_succeed: falsesudo=true, failures were fatalFailure handling: Simplified from
next if !sudo && !result.success?tonext unless result.success?File removal operations: Changed from
command.run!tocommand.runwithmust_succeed: falsefor:.plistfiles from/Library/LaunchAgents/and/Library/LaunchDaemons/launchctl unloadTests (
Library/Homebrew/test/cask/artifact/shared_examples/uninstall_zap.rb)must_succeed: falsefor sudo operationsImpact
This change ensures that cask uninstallation proceeds even when launchctl service removal operations fail due to permission issues or other errors. The uninstall process will attempt to remove services but won't abort if unsuccessful, improving the user experience for those without admin access or who choose not to provide sudo credentials.
Fixes #<issue_number>
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.