TypeError on data_bag_item helper

The error is:

TypeError

···

can’t convert Array into String

It means it is aspecting a string but instead it finds an array and an array cannot be automatically converted into a string

On Friday, 3 January 2014 23:40:47 UTC, ju...@gmail.com wrote:

I’m working on a very simple wrapper recipe for Sensu and am having a problem when trying to test with Vagrant. The recipes I’m using are dead simple at the moment because I’m just working on the very basics (working on a demo of cookbook management with Chef server).

=== sensu-cookbook::default ===

include_recipe ‘sensu::default’

=== sensu-cookbook::server ===

include_recipe ‘sensu::rabbitmq’

include_recipe ‘sensu::redis’

gem_package ‘sensu-plugin’ do

version node.alti.sensu.plugin_version

end

include_recipe ‘sensu::api_service’

include_recipe ‘sensu::dashboard_service’

include_recipe ‘sensu-cookbook::default’

I’m specifically targeting version 0.8.0 of the upstream sens cookbook. I was able to work around the exception by putting a rescue block around lines 34-39 of a local copy of libraries/sensu_helpers.rb but that’s definitely not the right thing. Since I don’t have any data bags, I would expect it throw a “Chef::Exceptions::InvalidDataBagPath” error and be caught at line 49 and then trigger the missing_ok test and move on. Alas, that doesn’t seem to be happening and I end up with this:

================================================================================

Recipe Compile Error in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/sensu-cookbook/recipes/server.rb

================================================================================

TypeError


can’t convert Array into String

Cookbook Trace:


/tmp/vagrant-chef-1/chef-solo-1/cookbooks/sensu/libraries/sensu_helpers.rb:36:in `data_bag_item’

/tmp/vagrant-chef-1/chef-solo-1/cookbooks/sensu/recipes/rabbitmq.rb:58:in `from_file’

/tmp/vagrant-chef-1/chef-solo-1/cookbooks/sensu-cookbook/recipes/server.rb:9:in `from_file’

Relevant File Content:


/tmp/vagrant-chef-1/chef-solo-1/cookbooks/sensu/libraries/sensu_helpers.rb:

29: “gem”

30: end

31: end

32:

33: def data_bag_item(item, missing_ok=false)

34: Chef::Log.info “Item: #{item}”

35: Chef::Log.info “Missing OK: #{missing_ok}”

36>> raw_hash = Chef::DataBagItem.load(“sensu”, item)

37: encrypted = raw_hash.detect do |key, value|

38: if value.is_a?(Hash)

39: value.has_key?(“encrypted_data”)

40: end

41: end

42: if encrypted

43: secret = Chef::EncryptedDataBagItem.load_secret

44: Chef::EncryptedDataBagItem.new(raw_hash, secret)

45: else

As you can see in the dump, I added some debug statements to see if there was something wrong with the data making into the helper but they looks fine (objects types String and TrueClass, respectively). Has anyone else run into this? I’ve compared my work to the monitor wrapper cookbook and haven’t yet found a smoking gun that would explain this problem but it never makes it to line 34 (of the unmodified file, not mine).