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?
to_json
is a private method here and it's called without any arguments:
https://github.com/johnbellone/consul-cookbook/blob/793a33ab758a31a29bb2ee3887aa189f33132888/libraries/consul_definition.rb#L59
https://github.com/johnbellone/consul-cookbook/blob/cbe87ae6cd0ff64bfe2edc8b6c487e5a26322093/libraries/consul_watch.rb#L54
https://github.com/johnbellone/consul-cookbook/blob/ac38fd73b3e1f2fe3b34afdd8fb3e384a5818574/libraries/consul_config.rb#L259
All tests are passing fine.
Please, provide a scenario how can we reproduce this issue.
@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
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.
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.