diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2019-08-23 15:01:12 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2019-08-26 14:09:12 -0700 |
commit | a8a6ea0734998c32e015259b385ee4fc3e9ccfa8 (patch) | |
tree | b743de046fb7455920cd034df42c642e2ed857ab /lib/chef/node.rb | |
parent | dd0009d7e77f192cadb1632f2159a6dbc880980f (diff) | |
download | chef-a8a6ea0734998c32e015259b385ee4fc3e9ccfa8.tar.gz |
Fix node[:cookbooks] attribute
closes #8817
Note that if any calling code winds up seeing this error message:
```
NoMethodError: undefined method `set_cookbook_attribute' for nil:NilClass
```
That means that the cookbook_collection was set before the node was
set on the run_context. That wouldn't be a bug in core chef, that must
be fixed in the caller to reverse the order of operations.
Since I only made the positional arguments to the run_context constructor
optional in Chef-15.0 though I don't expect this breaks any existing code
written in the past month or two, but if anything crops up in the future,
consider this a definitive statement that the caller must reverse the
order of their operations and this error being thrown is a feature not
a bug to be fixed.
(The fact that we silently aborted rather than threw a NoMethodError on
NilClass meant that we shipped this defect -- sometimes defensive
programming can be overly defensive and swallow real errors).
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/node.rb')
-rw-r--r-- | lib/chef/node.rb | 2 |
1 files changed, 0 insertions, 2 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb index ec20fbee86..1e5d3a8d59 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -87,8 +87,6 @@ class Chef # after the run_context has been set on the node, go through the cookbook_collection # and setup the node[:cookbooks] attribute so that it is published in the node object def set_cookbook_attribute - return unless run_context.cookbook_collection - run_context.cookbook_collection.each do |cookbook_name, cookbook| automatic_attrs[:cookbooks][cookbook_name][:version] = cookbook.version end |