From 4b9373f694587bcd074472d149448cfef6344f93 Mon Sep 17 00:00:00 2001 From: brad2014 Date: Mon, 21 Apr 2025 12:35:25 +0200 Subject: [PATCH] Homebrew: Emit a useful error message if brew info reports a package tap is null. (#10013) * Fix #10012. Homebrew: Emit a useful error message if a package tap is null. This can happen if an installed package is subsequently removed from the tap (e.g. it is withdrawn by homebrew). * Added changelogs fragment for PR 10013 * Do not raise error when tap is null in package_detail pylint: remove trailing whitespace * Minor: Update plugins/modules/homebrew.py Co-authored-by: Felix Fontein * Minor: Update changelogs/fragments/10012-improve-error-handling-homebrew-missing-tap.yml Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * Update plugins/modules/homebrew.py Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> --- ...12-improve-error-handling-homebrew-missing-tap.yml | 2 ++ plugins/modules/homebrew.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/10012-improve-error-handling-homebrew-missing-tap.yml diff --git a/changelogs/fragments/10012-improve-error-handling-homebrew-missing-tap.yml b/changelogs/fragments/10012-improve-error-handling-homebrew-missing-tap.yml new file mode 100644 index 0000000000..443be8358c --- /dev/null +++ b/changelogs/fragments/10012-improve-error-handling-homebrew-missing-tap.yml @@ -0,0 +1,2 @@ +bugfixes: + - homebrew - emit a useful error message if ``brew info`` reports a package tap is ``null`` (https://github.com/ansible-collections/community.general/pull/10013, https://github.com/ansible-collections/community.general/issues/10012). diff --git a/plugins/modules/homebrew.py b/plugins/modules/homebrew.py index bdc6f65724..25d4fc37e2 100644 --- a/plugins/modules/homebrew.py +++ b/plugins/modules/homebrew.py @@ -399,10 +399,15 @@ class Homebrew(object): name = package_detail["name"] full_name = package_detail["full_name"] - tapped_name = package_detail["tap"] + "/" + name + # Issue https://github.com/ansible-collections/community.general/issues/9803: + # name can include the tap as a prefix, in order to disambiguate, + # e.g. casks from identically named formulae. + # + # Issue https://github.com/ansible-collections/community.general/issues/10012: + # package_detail["tap"] is None if package is no longer available. + tapped_name = [package_detail["tap"] + "/" + name] if package_detail["tap"] else [] aliases = package_detail.get("aliases", []) - - package_names = set([name, full_name, tapped_name] + aliases) + package_names = set([name, full_name] + tapped_name + aliases) # Finally, identify which of all those package names was the one supplied by the user. package_names = package_names & set(self.packages)