# Re: Really? What am I missing?

**URL:** https://discourse.chef.io/t/re-really-what-am-i-missing/3374
**Category:** Chef Infra (archive)
**Created:** [December 7, 2012, 5:53am UTC](https://discourse.chef.io/t/re-really-what-am-i-missing/3374 "2012-12-07T05:53:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Warren\_Bain](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/warren_bain/32/538_2.png) [@Warren\_Bain](https://discourse.chef.io/u/Warren_Bain)
#### Post date: [December 7, 2012, 5:53am UTC](https://discourse.chef.io/t/re-really-what-am-i-missing/3374/1 "2012-12-07T05:53:06Z")

</div>

Mark,

As a chef n00b I get lots of these. The attribute you are referencing doesn’t exist and so node[:sgbase] which is nil doesn’t have a method [:branch]. Hence the slightly confusing error.

Wazza

Warren Bain  
[http://ninefold.com](http://ninefold.com)  
Australia’s cloud  
direct: +61 2 8221 7729  
mobile: +61 414 867 559  
follow: [http://twitter.com/thoughtcroft](http://twitter.com/thoughtcroft)

Mark J Bradakis [mark@bradakis.com](mailto:mark@bradakis.com) wrote:  
So I get this error:

## NoMethodError

undefined method `[]’ for nil:NilClass

Which comes from this line:

627\>\> revision node[:sgbase][:branch]

Called by a recipe in a file that does this:

“cookbook\_versions”: {  
“cpan”: “= 1.0.0”,  
“apt”: “= 1.0.0”,  
“sgbase”: “= 1.0.0”,  
“branch”: “= 1.0.0”  
…

sgbase and branch ARE defined - why the NULL error?

mjb.

---

<div class="post-metadata">

### Author: ![Brasic\_Carl](https://avatars.discourse-cdn.com/v4/letter/b/f475e1/32.png) [@Brasic\_Carl](https://discourse.chef.io/u/Brasic_Carl)
#### Post date: [December 7, 2012, 6:33pm UTC](https://discourse.chef.io/t/re-really-what-am-i-missing/3374/2 "2012-12-07T18:33:23Z")

</div>

One thing I find helpful when debugging these sort of issues is pry[1].

If the node you're running chef-client on has the pry gem installed  
and available to chef, you can just include

```
require 'pry'
binding.pry

```

in your recipe wherever you want to set up a breakpoint -- when  
chef-client runs, you get dropped into an irb-like shell at that point  
in the code where you can inspect variables like node and run  
arbitrary code in the context of the compile phase (or in execute  
phase if you invoke pry in a ruby\_block). Type 'exit' and the chef  
run will continue. You can even do things like update the node  
variable to test that some change you might later make in  
attributes.rb will work.

It's much more convenient than the debug statement/re-upload  
strategy that I was using before.

Carl

[1] [GitHub - pry/pry: A runtime developer console and IRB alternative with powerful introspection capabilities.](https://github.com/pry/pry)

On Thu, Dec 6, 2012 at 11:53 PM, Warren Bain [Warren@ninefold.com](mailto:Warren@ninefold.com) wrote:

> Mark,
> 
> As a chef n00b I get lots of these. The attribute you are referencing doesn't exist and so node[:sgbase] which is nil doesn't have a method [:branch]. Hence the slightly confusing error.
> 
> Wazza
> 
> Warren Bain  
> [http://ninefold.com](http://ninefold.com)  
> Australia's cloud  
> direct: +61 2 8221 7729  
> mobile: +61 414 867 559  
> follow: [http://twitter.com/thoughtcroft](http://twitter.com/thoughtcroft)
> 
> Mark J Bradakis [mark@bradakis.com](mailto:mark@bradakis.com) wrote:  
> So I get this error:
> 
> ## NoMethodError
> 
> undefined method `' for nil:NilClass
> 
> Which comes from this line:
> 
> 627\>\> revision node[:sgbase][:branch]
> 
> Called by a recipe in a file that does this:
> 
> "cookbook\_versions": {  
> "cpan": "= 1.0.0",  
> "apt": "= 1.0.0",  
> "sgbase": "= 1.0.0",  
> "branch": "= 1.0.0"  
> ...
> 
> sgbase and branch ARE defined - why the NULL error?
> 
> mjb.

---

<div class="post-metadata">

### Author: ![dcondomitti](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/dcondomitti/32/104_2.png) [@dcondomitti](https://discourse.chef.io/u/dcondomitti)
#### Post date: [December 7, 2012, 8:34pm UTC](https://discourse.chef.io/t/re-really-what-am-i-missing/3374/3 "2012-12-07T20:34:18Z")

</div>

You can also do the same thing with shef and isolate individual recipes.

[http://wiki.opscode.com/display/chef/Shef](http://wiki.opscode.com/display/chef/Shef)

> **[An Introduction to Shef, the Chef Shell - Julian Dunn's Blog](https://www.juliandunn.net/2012/10/19/an-introduction-to-shef-the-chef-shell/)**
>
> Earlier this week I gave a talk at the Chef-NYC meetup about Shef, the Chef Shell. Although it was more of an interactive demo rather than a traditional presentation, I’ve put the slides up nonetheless. I’ve also been meaning to post some notes from...

[http://stevendanna.github.com/blog/2012/01/28/shef-debugging-tips-1/](http://stevendanna.github.com/blog/2012/01/28/shef-debugging-tips-1/)

> **[GitHub - bryanwb/chef-rewind: monkeypatch chef to edit existing resources in...](https://github.com/bryanwb/chef-rewind)**
>
> monkeypatch chef to edit existing resources in place - GitHub - bryanwb/chef-rewind: monkeypatch chef to edit existing resources in place

On Friday, December 7, 2012 at 10:33 AM, Brasic, Carl wrote:

> One thing I find helpful when debugging these sort of issues is pry[1].
> 
> If the node you're running chef-client on has the pry gem installed  
> and available to chef, you can just include
> 
> require 'pry'  
> binding.pry
> 
> in your recipe wherever you want to set up a breakpoint -- when  
> chef-client runs, you get dropped into an irb-like shell at that point  
> in the code where you can inspect variables like node and run  
> arbitrary code in the context of the compile phase (or in execute  
> phase if you invoke pry in a ruby\_block). Type 'exit' and the chef  
> run will continue. You can even do things like update the node  
> variable to test that some change you might later make in  
> attributes.rb will work.
> 
> It's much more convenient than the debug statement/re-upload  
> strategy that I was using before.
> 
> Carl
> 
> [1] [GitHub - pry/pry: A runtime developer console and IRB alternative with powerful introspection capabilities.](https://github.com/pry/pry)
> 
> On Thu, Dec 6, 2012 at 11:53 PM, Warren Bain \<[Warren@ninefold.com](mailto:Warren@ninefold.com) ([mailto:Warren@ninefold.com](mailto:Warren@ninefold.com))\> wrote:
> 
> > Mark,
> > 
> > As a chef n00b I get lots of these. The attribute you are referencing doesn't exist and so node[:sgbase] which is nil doesn't have a method [:branch]. Hence the slightly confusing error.
> > 
> > Wazza
> > 
> > Warren Bain  
> > [http://ninefold.com](http://ninefold.com)  
> > Australia's cloud  
> > direct: +61 2 8221 7729  
> > mobile: +61 414 867 559  
> > follow: [http://twitter.com/thoughtcroft](http://twitter.com/thoughtcroft)
> > 
> > Mark J Bradakis \<[mark@bradakis.com](mailto:mark@bradakis.com) ([mailto:mark@bradakis.com](mailto:mark@bradakis.com))\> wrote:  
> > So I get this error:
> > 
> > ## NoMethodError
> > 
> > undefined method `' for nil:NilClass
> > 
> > Which comes from this line:
> > 
> > 627\>\> revision node[:sgbase][:branch]
> > 
> > Called by a recipe in a file that does this:
> > 
> > "cookbook\_versions": {  
> > "cpan": "= 1.0.0",  
> > "apt": "= 1.0.0",  
> > "sgbase": "= 1.0.0",  
> > "branch": "= 1.0.0"  
> > ...
> > 
> > sgbase and branch ARE defined - why the NULL error?
> > 
> > mjb.
