4
votes

Context - We have a massive amount of Chef attributes to perform our install, something like 3000+ have now been defined and change per environment.

Problem - Sometimes a Chef recipe will reference a non-existent attribute node[:mystuff][:typo]. This results in the following error:

Recipe Compile Error in /var/chef/cache/cookbooks/<yyy>/recipes/something.rb
undefined method '[]' for nil:NilClass

This is a worthless error because it doesn't let me know exactly what node/attribute is missing. Even running with chef-client -l debug doesn't help. knife cookbook test <x> doesn't help because syntactically it is correct. Is there a way to get it to print out the exact line number that is causing the error? The recipe may contain 10s or 100s of attributes so it is a huge time waster going through line by line to discover a typo.

1

1 Answers

6
votes

I wrote Chef Sugar's deep_fetch method precisely for this reason.

The error you are getting is just the by-product of Ruby hashes. For more information on deep_fetch, you can also see my blog post on the subject: https://sethvargo.com/delicious-new-chef-sugars/