infochimps/cluster_chef — Issue #80: Tripping over a syntax error in meta-cookbooks/cluster_chef/libraries/component.rb
Author: pcn
Created: 2011-12-09 05:41:47+00:00
State: open

I'm getting the following in a chef run, trying to use the cassandra-node cookbook:

Generated at Fri Dec 09 04:59:24 +0000 2011
SyntaxError: /var/chef/cache/cookbooks/cluster_chef/libraries/component.rb:94: syntax error, unexpected '=', expecting '|'
define_method(klass.handle) do |name, val=nil, &block|
^
/var/chef/cache/cookbooks/cluster_chef/libraries/component.rb:94: Can't assign to nil
define_method(klass.handle) do |name, val=nil, &block|
^
/var/chef/cache/cookbooks/cluster_chef/libraries/component.rb:152: syntax error, unexpected kEND, expecting $end
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:82:in `load'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:82
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:120:in `call'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:120:in `foreach_cookbook_load_segment'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:119:in `each'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:119:in `foreach_cookbook_load_segment'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:117:in `each'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:117:in `foreach_cookbook_load_segment'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:80:in `load_libraries'
/usr/lib/ruby/vendor_ruby/chef/run_context.rb:57:in `load'
/usr/lib/ruby/vendor_ruby/chef/client.rb:195:in `setup_run_context'
/usr/lib/ruby/vendor_ruby/chef/client.rb:159:in `run'
/usr/lib/ruby/vendor_ruby/chef/application/client.rb:239:in `run_application'
/usr/lib/ruby/vendor_ruby/chef/application/client.rb:229:in `loop'
/usr/lib/ruby/vendor_ruby/chef/application/client.rb:229:in `run_application'
/usr/lib/ruby/vendor_ruby/chef/application.rb:67:in `run'
/usr/bin/chef-client:25

This looks like it's coming from https://github.com/infochimps/cluster_chef/commit/5000633413468db23cd00061ee7dd2d246bcf100.

The code looks like this:

# add this class to the list of registered aspects
def self.has_aspect(klass)
self.aspect_types[klass.plural_handle] = klass
dsl_attr(klass.plural_handle, :kind_of => Mash, :dup_default => Mash.new)
define_method(klass.handle) do |name, val=nil, &block|
hsh = self.send(klass.plural_handle)
#
hsh[name] = val if val
# instance eval if block given (auto-vivify if necessary
if block
hsh[name] ||= klass.new(self, name)
hsh[name].instance_eval(&block)
end
#
hsh[name]
end
end

It looks like default arguments for define_method aren't valid, at least in ruby 1.8?