sous-chefs / consul

Development repository for the consul cookbook

Home Page:https://supermarket.chef.io/cookbooks/consul

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom resources do not implement to_json correctly

Wing924 opened this issue · comments

to_json interface should be def to_json(options = nil) but was def to_json
It causes:

 #<ArgumentError: wrong number of arguments (given 1, expected 0)>
    /var/chef/cache/cookbooks/consul/libraries/consul_config.rb:133:in `to_json'

AFAIK, it's not supposed that this method will be called with arguments. When does this issue happen?

@legal90 JSON.generate or .to_json will call that method with args.

@legal90
Create a Chef Handler like this:

class Chef; class Handler
	def report
                # The data method is used to return the Hash representation of the run_status object

		# these lines will raise error
		data.to_json 
		JSON.generate data
	end
end; end

ref. https://docs.chef.io/handlers.html

OK, now I got it.
So, the issue is caused by the method name collision. The proper way to fix it is just renaming our to_json methods to something unique. For example, to params_to_json.

I will send a PR.

@Wing924 Please, verify your handler with this fix applied: #476

commented

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.