summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-04-17 17:05:43 -0700
committerTim Smith <tsmith84@gmail.com>2020-04-17 17:05:43 -0700
commitc25eb20b2b1e4676118d7583b7f17394c9deec41 (patch)
treedbab2a32f38bed37b38c3a11df620ae4743a339e /lib
parent0cf9f8817e5b493cf93949b69a580dd45b39e021 (diff)
downloadchef-c25eb20b2b1e4676118d7583b7f17394c9deec41.tar.gz
Use lamont's magic error handling
Tiny tweak to grab the first item so we actually get the hash back in the error handling. Given: ```ruby package %w{curl totally_junk_pkg} do action :upgrade end ``` ``` * No candidate version available for totally_junk_pkg ================================================================================ Error executing action `upgrade` on resource 'homebrew_package[curl, totally_junk_pkg]' ================================================================================ Chef::Exceptions::Package ------------------------- No candidate version available for totally_junk_pkg ``` Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/provider/package/homebrew.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/chef/provider/package/homebrew.rb b/lib/chef/provider/package/homebrew.rb
index d0321b2175..012bcdbb13 100644
--- a/lib/chef/provider/package/homebrew.rb
+++ b/lib/chef/provider/package/homebrew.rb
@@ -96,9 +96,21 @@ class Chef
# convert the array of hashes into a hash where the key is the package name
cmd_output = brew_cmd_output(command_array, allow_failure: true)
- return {} if cmd_output.empty? # empty std_out == bad package queried
- Hash[Chef::JSONCompat.from_json(cmd_output).collect { |pkg| [pkg["name"], pkg] }]
+ if cmd_output.empty?
+ # we had some kind of failure so we need to iterate through each package to find them
+ package_name_array.each_with_object({}) do |package_name, hsh|
+ cmd_output = brew_cmd_output("info", "--json=v1", package_name, allow_failure: true)
+ if cmd_output.empty?
+ hsh[package_name] = {}
+ else
+ json = Chef::JSONCompat.from_json(cmd_output).first
+ hsh[json["name"]] = json
+ end
+ end
+ else
+ Hash[Chef::JSONCompat.from_json(cmd_output).collect { |pkg| [pkg["name"], pkg] }]
+ end
end
end