One thing to point out - if node['environment']
hasn't been set at all, your example would fail as it is. Here's the output I got:
[Tue, 16 Oct 2012 02:40:31 +0000] INFO: Starting Chef Run for vagrant.int.housepub.org
[Tue, 16 Oct 2012 02:40:31 +0000] INFO: Running start handlers
[Tue, 16 Oct 2012 02:40:31 +0000] INFO: Start handlers complete.
[Tue, 16 Oct 2012 02:40:31 +0000] ERROR: Running exception handlers
[Tue, 16 Oct 2012 02:40:31 +0000] ERROR: Exception handlers complete
[Tue, 16 Oct 2012 02:40:31 +0000] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[Tue, 16 Oct 2012 02:10:38 +0000] FATAL: NoMethodError: undefined method `[]' for nil:NilClass
But that's not very helpful, and it's not always enough. Perhaps you want to do some extra validation of the attribute. In that case, you can put something like this into your recipe:
unless node['environment']['url'] && node['environment']['url'].size > 5
Chef::Application.fatal!("The URL attribute isn't long enough.")
end
Now, the Chef run will give you a more helpful message when it fails:
[Tue, 16 Oct 2012 02:41:36 +0000] INFO: Starting Chef Run for vagrant.int.housepub.org
[Tue, 16 Oct 2012 02:41:36 +0000] INFO: Running start handlers
[Tue, 16 Oct 2012 02:41:36 +0000] INFO: Start handlers complete.
[Tue, 16 Oct 2012 02:41:36 +0000] FATAL: The URL attribute isn't long enough.
[Tue, 16 Oct 2012 02:41:36 +0000] ERROR: Running exception handlers
[Tue, 16 Oct 2012 02:41:36 +0000] ERROR: Exception handlers complete