# Debugging recipe for a specific incorrect file

**URL:** https://discourse.chef.io/t/debugging-recipe-for-a-specific-incorrect-file/6834
**Category:** Chef Infra (archive)
**Created:** [August 4, 2015, 9:21pm UTC](https://discourse.chef.io/t/debugging-recipe-for-a-specific-incorrect-file/6834 "2015-08-04T21:21:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Nikhil\_Shah](https://avatars.discourse-cdn.com/v4/letter/n/f17d59/32.png) [@Nikhil\_Shah](https://discourse.chef.io/u/Nikhil_Shah)
#### Post date: [August 4, 2015, 9:21pm UTC](https://discourse.chef.io/t/debugging-recipe-for-a-specific-incorrect-file/6834/1 "2015-08-04T21:21:35Z")

</div>

I've fried my brain going thru each configs and I can't for the life of me  
figure out where i messed up the configs. Is there a way to debug this  
within the recipe? I've checked data bags and roles and it seems like the  
error is saying I have a null value as hostgroup, but I don't see anything.

Recipe Compile Error in /var/chef/cache/cookbooks/nagios/recipes/server.rb

> ================================================================================
> 
> ## NoMethodError
> 
> undefined method `each' for nil:NilClass
> 
> ## Cookbook Trace:
> 
> /var/chef/cache/cookbooks/nagios/recipes/server.rb:156:in `block in from_file' /var/chef/cache/cookbooks/nagios/recipes/server.rb:155:in `each'  
> /var/chef/cache/cookbooks/nagios/recipes/server.rb:155:in `from\_file'
> 
> ## Relevant File Content:
> 
> /var/chef/cache/cookbooks/nagios/recipes/server.rb:  
> 149: unmanaged\_hosts = nagios\_bags.get('nagios\_unmanagedhosts')  
> 150: serviceescalations = nagios\_bags.get('nagios\_serviceescalations')  
> 151: contacts = nagios\_bags.get('nagios\_contacts')  
> 152: contactgroups = nagios\_bags.get('nagios\_contactgroups')  
> 153:  
> 154: # Add unmanaged host hostgroups to the hostgroups array if they  
> don't already exist  
> 155: unmanaged\_hosts.each do |host|  
> 156\>\> host['hostgroups'].each do |hg|  
> 157: if !hostgroups.include?(hg)  
> 158: hostgroups \<\< hg  
> 159: end  
> 160: end  
> 161: end  
> 162:  
> 163: # Load search defined Nagios hostgroups from the nagios\_hostgroups  
> data bag and find nodes  
> 164: hostgroup\_nodes= Hash.new  
> 165: hostgroup\_list = Array.new
> 
> [2015-08-04T17:05:01-04:00] ERROR: Running exception handlers  
> [2015-08-04T17:05:01-04:00] ERROR: Exception handlers complete  
> [2015-08-04T17:05:01-04:00] FATAL: Stacktrace dumped to  
> /var/chef/cache/chef-stacktrace.out  
> Chef Client failed. 0 resources updated  
> [2015-08-04T17:05:01-04:00] ERROR: undefined method `each' for nil:NilClass  
> [2015-08-04T17:05:01-04:00] FATAL: Chef::Exceptions::ChildConvergeError:  
> Chef run process exited unsuccessfully (exit code 1)  
> You have new mail in /var/spool/mail/root

--  
_Nikhil Shah_ • _System Administrator_  
[nshah@theorchard.com](mailto:nshah@theorchard.com) • _p._ (+1) 212 308-5648

THE ORCHARD _Distribution Done Right_  
23 E 4th St Fl 3, New York, NY 10003

> **[The Orchard](https://www.theorchard.com)**
>
> What started as a revolutionary music distribution company, continues to evolve but never loses sight of its main purpose: to empower creators to grow and adapt in the dynamic, global industry.

_Follow us:_ The Daily Rind [http://www.dailyrindblog.com/](http://www.dailyrindblog.com/) • Facebook  
[http://www.facebook.com/theorchard](http://www.facebook.com/theorchard) • Twitter  
[http://www.twitter.com/orchtweets](http://www.twitter.com/orchtweets) • YouTube  
[http://www.youtube.com/user/theorchard](http://www.youtube.com/user/theorchard) • LinkedIn  
[http://www.linkedin.com/company/the-orchard](http://www.linkedin.com/company/the-orchard)

_Privileged And Confidential Communication._ This electronic transmission,  
and any documents attached hereto, (a) are protected by the Electronic  
Communications Privacy Act (18 USC §§ 2510-2521), (b) may contain  
confidential and/or legally privileged information, and (c) are for the  
sole use of the intended recipient named above. If you have received this  
electronic message in error, please notify the sender and delete the  
electronic message. Any disclosure, copying, distribution, or use of the  
contents of the information received in error is strictly prohibited.

---

<div class="post-metadata">

### Author: ![Tobias\_Unsleber](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@Tobias\_Unsleber](https://discourse.chef.io/u/Tobias_Unsleber)
#### Post date: [August 4, 2015, 9:41pm UTC](https://discourse.chef.io/t/debugging-recipe-for-a-specific-incorrect-file/6834/2 "2015-08-04T21:41:25Z")

</div>

Hi Nikhil,

try using pretty print to produce verbose output.  
Check your objects if the contents are as expected.

# at recipe start

require 'pp'

insert after line 155

log pp host

Regards,  
Tobias

Am 04.08.2015 um 23:21 schrieb Nikhil Shah:

> I've fried my brain going thru each configs and I can't for the life  
> of me figure out where i messed up the configs. Is there a way to  
> debug this within the recipe? I've checked data bags and roles and it  
> seems like the error is saying I have a null value as hostgroup, but I  
> don't see anything.
> 
> ```
> Recipe Compile Error in
> /var/chef/cache/cookbooks/nagios/recipes/server.rb
> ================================================================================
> 
> NoMethodError
> -------------
> undefined method `each' for nil:NilClass
> 
> Cookbook Trace:
> ---------------
> /var/chef/cache/cookbooks/nagios/recipes/server.rb:156:in `block
> in from_file'
> /var/chef/cache/cookbooks/nagios/recipes/server.rb:155:in `each'
> /var/chef/cache/cookbooks/nagios/recipes/server.rb:155:in `from_file'
> 
> Relevant File Content:
> ----------------------
> /var/chef/cache/cookbooks/nagios/recipes/server.rb:
> 149: unmanaged_hosts = nagios_bags.get('nagios_unmanagedhosts')
> 150: serviceescalations =
> nagios_bags.get('nagios_serviceescalations')
> 151: contacts = nagios_bags.get('nagios_contacts')
> 152: contactgroups = nagios_bags.get('nagios_contactgroups')
> 153:
> 154: # Add unmanaged host hostgroups to the hostgroups array if
> they don't already exist
> 155: unmanaged_hosts.each do |host|
> 156>> host['hostgroups'].each do |hg|
> 157: if !hostgroups.include?(hg)
> 158: hostgroups << hg
> 159: end
> 160: end
> 161: end
> 162:
> 163: # Load search defined Nagios hostgroups from the
> nagios_hostgroups data bag and find nodes
> 164: hostgroup_nodes= Hash.new
> 165: hostgroup_list = Array.new
> 
> [2015-08-04T17:05:01-04:00] ERROR: Running exception handlers
> [2015-08-04T17:05:01-04:00] ERROR: Exception handlers complete
> [2015-08-04T17:05:01-04:00] FATAL: Stacktrace dumped to
> /var/chef/cache/chef-stacktrace.out
> Chef Client failed. 0 resources updated
> [2015-08-04T17:05:01-04:00] ERROR: undefined method `each' for
> nil:NilClass
> [2015-08-04T17:05:01-04:00] FATAL:
> Chef::Exceptions::ChildConvergeError: Chef run process exited
> unsuccessfully (exit code 1)
> You have new mail in /var/spool/mail/root
> 
> ```
> 
> --  
> _Nikhil Shah_ • /System Administrator/  
> [nshah@theorchard.com](mailto:nshah@theorchard.com) [mailto:nshah@theorchard.com](mailto:nshah@theorchard.com) • _p._(+1) 212  
> 308-5648
> 
> THE ORCHARD /Distribution Done Right/  
> 23 E 4^th St Fl 3, New York, NY 10003  
> [www.theorchard.com](http://www.theorchard.com) [http://www.theorchard.com/](http://www.theorchard.com/)
> 
> _Follow us:_ The Daily Rind [http://www.dailyrindblog.com/](http://www.dailyrindblog.com/) • Facebook  
> [http://www.facebook.com/theorchard](http://www.facebook.com/theorchard) • Twitter  
> [http://www.twitter.com/orchtweets](http://www.twitter.com/orchtweets) • YouTube  
> [http://www.youtube.com/user/theorchard](http://www.youtube.com/user/theorchard) • LinkedIn  
> [http://www.linkedin.com/company/the-orchard](http://www.linkedin.com/company/the-orchard)
> 
> _Privileged And Confidential Communication._ This electronic  
> transmission, and any documents attached hereto, (a) are protected by  
> the Electronic Communications Privacy Act (18 USC §§ 2510-2521), (b)  
> may contain confidential and/or legally privileged information, and  
> (c) are for the sole use of the intended recipient named above. If you  
> have received this electronic message in error, please notify the  
> sender and delete the electronic message. Any disclosure, copying,  
> distribution, or use of the contents of the information received in  
> error is strictly prohibited.

---

<div class="post-metadata">

### Author: ![Nikhil\_Shah](https://avatars.discourse-cdn.com/v4/letter/n/f17d59/32.png) [@Nikhil\_Shah](https://discourse.chef.io/u/Nikhil_Shah)
#### Post date: [August 5, 2015, 2:10pm UTC](https://discourse.chef.io/t/debugging-recipe-for-a-specific-incorrect-file/6834/3 "2015-08-05T14:10:54Z")

</div>

Tobias,

Awesome, that worked perfectly. Thanks!

On Tue, Aug 4, 2015 at 5:41 PM, Tobias Unsleber [tu@inline.de](mailto:tu@inline.de) wrote:

> Hi Nikhil,
> 
> try using pretty print to produce verbose output.  
> Check your objects if the contents are as expected.
> 
> # at recipe start
> 
> require 'pp'
> 
> insert after line 155
> 
> log pp host
> 
> Regards,  
> Tobias
> 
> Am 04.08.2015 um 23:21 schrieb Nikhil Shah:
> 
> I've fried my brain going thru each configs and I can't for the life of me  
> figure out where i messed up the configs. Is there a way to debug this  
> within the recipe? I've checked data bags and roles and it seems like the  
> error is saying I have a null value as hostgroup, but I don't see  
> anything.
> 
> Recipe Compile Error in /var/chef/cache/cookbooks/nagios/recipes/server.rb
> 
> > ================================================================================
> > 
> > ## NoMethodError
> > 
> > undefined method `each' for nil:NilClass
> > 
> > ## Cookbook Trace:
> > 
> > /var/chef/cache/cookbooks/nagios/recipes/server.rb:156:in `block in from_file' /var/chef/cache/cookbooks/nagios/recipes/server.rb:155:in `each'  
> > /var/chef/cache/cookbooks/nagios/recipes/server.rb:155:in `from\_file'
> > 
> > ## Relevant File Content:
> > 
> > /var/chef/cache/cookbooks/nagios/recipes/server.rb:  
> > 149: unmanaged\_hosts = nagios\_bags.get('nagios\_unmanagedhosts')  
> > 150: serviceescalations = nagios\_bags.get('nagios\_serviceescalations')  
> > 151: contacts = nagios\_bags.get('nagios\_contacts')  
> > 152: contactgroups = nagios\_bags.get('nagios\_contactgroups')  
> > 153:  
> > 154: # Add unmanaged host hostgroups to the hostgroups array if they  
> > don't already exist  
> > 155: unmanaged\_hosts.each do |host|  
> > 156\>\> host['hostgroups'].each do |hg|  
> > 157: if !hostgroups.include?(hg)  
> > 158: hostgroups \<\< hg  
> > 159: end  
> > 160: end  
> > 161: end  
> > 162:  
> > 163: # Load search defined Nagios hostgroups from the nagios\_hostgroups  
> > data bag and find nodes  
> > 164: hostgroup\_nodes= Hash.new  
> > 165: hostgroup\_list = Array.new
> > 
> > [2015-08-04T17:05:01-04:00] ERROR: Running exception handlers  
> > [2015-08-04T17:05:01-04:00] ERROR: Exception handlers complete  
> > [2015-08-04T17:05:01-04:00] FATAL: Stacktrace dumped to  
> > /var/chef/cache/chef-stacktrace.out  
> > Chef Client failed. 0 resources updated  
> > [2015-08-04T17:05:01-04:00] ERROR: undefined method `each' for  
> > nil:NilClass  
> > [2015-08-04T17:05:01-04:00] FATAL: Chef::Exceptions::ChildConvergeError:  
> > Chef run process exited unsuccessfully (exit code 1)  
> > You have new mail in /var/spool/mail/root
> 
> --  
> _Nikhil Shah_ • _System Administrator_  
> [nshah@theorchard.com](mailto:nshah@theorchard.com)[nshah@theorchard.com](mailto:nshah@theorchard.com) • _p._ (+1) 212 308-5648
> 
> THE ORCHARD _Distribution Done Right_  
> 23 E 4th St Fl 3, New York, NY 10003  
> [http://www.theorchard.com/](http://www.theorchard.com/)[www.theorchard.com](http://www.theorchard.com)
> 
> _Follow us:_ The Daily Rind [http://www.dailyrindblog.com/](http://www.dailyrindblog.com/) • Facebook  
> [http://www.facebook.com/theorchard](http://www.facebook.com/theorchard) • Twitter  
> [http://www.twitter.com/orchtweets](http://www.twitter.com/orchtweets) • YouTube  
> [http://www.youtube.com/user/theorchard](http://www.youtube.com/user/theorchard) • LinkedIn  
> [http://www.linkedin.com/company/the-orchard](http://www.linkedin.com/company/the-orchard)
> 
> _Privileged And Confidential Communication._ This electronic  
> transmission, and any documents attached hereto, (a) are protected by the  
> Electronic Communications Privacy Act (18 USC §§ 2510-2521), (b) may  
> contain confidential and/or legally privileged information, and (c) are for  
> the sole use of the intended recipient named above. If you have received  
> this electronic message in error, please notify the sender and delete the  
> electronic message. Any disclosure, copying, distribution, or use of the  
> contents of the information received in error is strictly prohibited.

--  
_Nikhil Shah_ • _System Administrator_  
[nshah@theorchard.com](mailto:nshah@theorchard.com) • _p._ (+1) 212 308-5648

THE ORCHARD _Distribution Done Right_  
23 E 4th St Fl 3, New York, NY 10003

> **[The Orchard](https://www.theorchard.com/)**
>
> What started as a revolutionary music distribution company, continues to evolve but never loses sight of its main purpose: to empower creators to grow and adapt in the dynamic, global industry.

_Follow us:_ The Daily Rind [http://www.dailyrindblog.com/](http://www.dailyrindblog.com/) • Facebook  
[http://www.facebook.com/theorchard](http://www.facebook.com/theorchard) • Twitter  
[http://www.twitter.com/orchtweets](http://www.twitter.com/orchtweets) • YouTube  
[http://www.youtube.com/user/theorchard](http://www.youtube.com/user/theorchard) • LinkedIn  
[http://www.linkedin.com/company/the-orchard](http://www.linkedin.com/company/the-orchard)

_Privileged And Confidential Communication._ This electronic transmission,  
and any documents attached hereto, (a) are protected by the Electronic  
Communications Privacy Act (18 USC §§ 2510-2521), (b) may contain  
confidential and/or legally privileged information, and (c) are for the  
sole use of the intended recipient named above. If you have received this  
electronic message in error, please notify the sender and delete the  
electronic message. Any disclosure, copying, distribution, or use of the  
contents of the information received in error is strictly prohibited.
