summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2021-10-22 14:03:16 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2021-10-22 14:03:16 -0700
commit4646a4b9d28c19cc750907825cc972f4722e6316 (patch)
treed96c254c3511a2ecce485cb1b1454737102ff860 /lib/chef
parentce70c573c79d966ba94fe7992750fcf470068864 (diff)
downloadchef-4646a4b9d28c19cc750907825cc972f4722e6316.tar.gz
Fix reporting/data_collector for @recipe_fileslcg/fix-reporting-for-recipe-files
When individual recipes are invoked like 'chef-client ./whatever.rb' those files get a cookbook_name of `@recipe_files` which is a magic value that nees to be handled specially to avoid the reporting classes from blowing up. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/data_collector/run_end_message.rb2
-rw-r--r--lib/chef/resource.rb2
-rw-r--r--lib/chef/resource_reporter.rb2
3 files changed, 3 insertions, 3 deletions
diff --git a/lib/chef/data_collector/run_end_message.rb b/lib/chef/data_collector/run_end_message.rb
index 91cf21e643..48b1d55aff 100644
--- a/lib/chef/data_collector/run_end_message.rb
+++ b/lib/chef/data_collector/run_end_message.rb
@@ -128,7 +128,7 @@ class Chef
if new_resource.cookbook_name
hash["cookbook_name"] = new_resource.cookbook_name
- hash["cookbook_version"] = new_resource.cookbook_version.version
+ hash["cookbook_version"] = new_resource.cookbook_version&.version
hash["recipe_name"] = new_resource.recipe_name
end
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 517c30bc19..e7ac91594f 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -1508,7 +1508,7 @@ class Chef
# @return Chef::CookbookVersion The cookbook in which this Resource was defined.
#
def cookbook_version
- if cookbook_name
+ if cookbook_name && cookbook_name != "@recipe_files"
run_context.cookbook_collection[cookbook_name]
end
end
diff --git a/lib/chef/resource_reporter.rb b/lib/chef/resource_reporter.rb
index c6a7be133f..242a6e9f0f 100644
--- a/lib/chef/resource_reporter.rb
+++ b/lib/chef/resource_reporter.rb
@@ -41,7 +41,7 @@ class Chef
as_hash["result"] = action_record.action.to_s
if new_resource.cookbook_name
as_hash["cookbook_name"] = new_resource.cookbook_name
- as_hash["cookbook_version"] = new_resource.cookbook_version.version
+ as_hash["cookbook_version"] = new_resource.cookbook_version&.version
end
as_hash