Skip to content

Catch cask errors to continue cleanup in install, upgrade, reinstall, and uninstall#21615

Merged
MikeMcQuaid merged 2 commits intoHomebrew:mainfrom
koddsson:fix-cask-halting-issue
Feb 23, 2026
Merged

Catch cask errors to continue cleanup in install, upgrade, reinstall, and uninstall#21615
MikeMcQuaid merged 2 commits intoHomebrew:mainfrom
koddsson:fix-cask-halting-issue

Conversation

@koddsson
Copy link
Contributor

@koddsson koddsson commented Feb 23, 2026

Summary

  • Wrap cask operations in install, upgrade, reinstall, and uninstall commands with begin/rescue blocks that call ofail instead of letting exceptions propagate
  • This prevents cask errors from skipping cleanup, pkgconf reinstall, and message display
  • Matches how formula upgrades already handle BuildError

Test plan

  • Added unit test for uninstall catching cask errors and setting Homebrew.failed
  • Added unit test for upgrade catching cask errors and setting Homebrew.failed
  • brew tests --online --changed passes
  • brew typecheck passes
  • brew style --fix --changed passes

🤖 Generated with Claude Code

koddsson and others added 2 commits February 23, 2026 18:22
When `Cask::Upgrade.upgrade_casks!` or `Cask::Reinstall.reinstall_casks`
raises, the exception now gets caught with `ofail` (which sets
`Homebrew.failed = true`) instead of propagating up and skipping
cleanup, pkgconf reinstall, and message display.

This matches how formula upgrades already handle `BuildError`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extend the same pattern from the previous commit to `uninstall` and
the new-cask install path in `install`.

In `uninstall`, both `Cask::Uninstall.uninstall_casks` and
`Cask::Installer#zap` can raise, which would skip
`Cleanup.autoremove`.

In `install`, the `new_casks.each` loop calling
`Cask::Installer#install` can raise, which would skip formula
installations, `Cleanup.periodic_clean!`, and message display.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good when 🟢, thanks @koddsson!

@koddsson
Copy link
Contributor Author

Hello! I hope I've followed all the guidance on LLMs as well as the other contributing info.

The PR description doesn't really go into detail for this but I'm trying to make sure that brew continues to uninstall the rest of the casks when uninstalling a list of casks like this:

brew uninstall shodan-public/shodan/geonet cirruslabs/cli/softnet go-task/tap/go-task danielgatis/imgcat/imgcat cirruslabs/cli/tart kegworks-app/kegworks/kegworks koddsson/wallpapers/wallpapers

The error that is thrown is:

Error: No available formula or cask with the name "kegworks-app/kegworks/kegworks".

And everything is still installed. I'm fine with the one cask erroring but I wish also uninstalled the rest.

Now, maybe there's a good reason for this but I figured I could try starting on a fix with a LLM since I'm not super versed with the codebase. IF this is something that we'd like to have in brew I'm happy to make changes with/without LLM or I can even redo this whole thing without a LLM but I find a PR often be a good jumping off point.

@koddsson
Copy link
Contributor Author

Looks good when 🟢, thanks @koddsson!

So quick! ❤️

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Feb 23, 2026
Merged via the queue into Homebrew:main with commit e8ecbc4 Feb 23, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants