TypeError on data_bag_item helper

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:


<details class='elided'>
<summary title='Show trimmed content'>&#183;&#183;&#183;</summary>

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

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).

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).

That, I understand. What I have yet to be able to debug is why it’s happening. I’m not sure if this is something in my environment, something in the cookbook or something in the version of Chef I’m using. My Vagrant machine uses ruby-1.9.3 (not sure of patch level right now) and Chef 11.8.2. I’ll try adding some additional debug code to the Chef libs and see if I can chase it down.

···

On Sat, Jan 4, 2014 at 3:23 AM, Riccardo Tacconi rtacconi@gmail.com wrote:

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).

–tucker

Digging further down the rabbit hole, I’ve found that it’s something with Chef::Config[:data_bag_path] in chef-XY.Z/lib/chef/data_bag.rb. I’ve checked the code for Chef 10 and Chef 11 and it hasn’t changed, so it’s obviously something wonky on my side. My debug statements have it as [“/tmp/vagrant-chef-1/chef-solo-1/data_bags”], which is obviously an array and not a string. Now I just need to sort out why it’s an array and not a string.

···

On Sat, Jan 4, 2014 at 11:04 AM, Tucker junk@gmail.com wrote:

That, I understand. What I have yet to be able to debug is why it’s happening. I’m not sure if this is something in my environment, something in the cookbook or something in the version of Chef I’m using. My Vagrant machine uses ruby-1.9.3 (not sure of patch level right now) and Chef 11.8.2. I’ll try adding some additional debug code to the Chef libs and see if I can chase it down.

–tucker

On Sat, Jan 4, 2014 at 3:23 AM, Riccardo Tacconi rtacconi@gmail.com wrote:

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).

–tucker

I think I’ve narrowed it down to a problem with Vagrant. Looking through the Vagrant chef_solo provisioner, it appears it should be writing out a string but I’m still getting an array. Unless I come full circle again and can point the blame elsewhere, I’ll let this thread here die.

···

On Mon, Jan 6, 2014 at 6:26 PM, Tucker junk@gmail.com wrote:

Digging further down the rabbit hole, I’ve found that it’s something with Chef::Config[:data_bag_path] in chef-XY.Z/lib/chef/data_bag.rb. I’ve checked the code for Chef 10 and Chef 11 and it hasn’t changed, so it’s obviously something wonky on my side. My debug statements have it as [“/tmp/vagrant-chef-1/chef-solo-1/data_bags”], which is obviously an array and not a string. Now I just need to sort out why it’s an array and not a string.

–tucker

On Sat, Jan 4, 2014 at 11:04 AM, Tucker junk@gmail.com wrote:

That, I understand. What I have yet to be able to debug is why it’s happening. I’m not sure if this is something in my environment, something in the cookbook or something in the version of Chef I’m using. My Vagrant machine uses ruby-1.9.3 (not sure of patch level right now) and Chef 11.8.2. I’ll try adding some additional debug code to the Chef libs and see if I can chase it down.

–tucker

On Sat, Jan 4, 2014 at 3:23 AM, Riccardo Tacconi rtacconi@gmail.com wrote:

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).

–tucker

Final update:

The problem was a combination of ruby-1.9.3p484 and Chef. Sadly, we’ve hit similar TypeErrors with this Ruby patch level in the past and I forgot. For anyone who comes across this, either use ruby-1.9.3p448 (don’t though, there’s a big security hole with floating points) or use ruby >= 2.0.0p353.

···

On Mon, Jan 6, 2014 at 6:49 PM, Tucker junk@gmail.com wrote:

I think I’ve narrowed it down to a problem with Vagrant. Looking through the Vagrant chef_solo provisioner, it appears it should be writing out a string but I’m still getting an array. Unless I come full circle again and can point the blame elsewhere, I’ll let this thread here die.

–tucker

On Mon, Jan 6, 2014 at 6:26 PM, Tucker junk@gmail.com wrote:

Digging further down the rabbit hole, I’ve found that it’s something with Chef::Config[:data_bag_path] in chef-XY.Z/lib/chef/data_bag.rb. I’ve checked the code for Chef 10 and Chef 11 and it hasn’t changed, so it’s obviously something wonky on my side. My debug statements have it as [“/tmp/vagrant-chef-1/chef-solo-1/data_bags”], which is obviously an array and not a string. Now I just need to sort out why it’s an array and not a string.

–tucker

On Sat, Jan 4, 2014 at 11:04 AM, Tucker junk@gmail.com wrote:

That, I understand. What I have yet to be able to debug is why it’s happening. I’m not sure if this is something in my environment, something in the cookbook or something in the version of Chef I’m using. My Vagrant machine uses ruby-1.9.3 (not sure of patch level right now) and Chef 11.8.2. I’ll try adding some additional debug code to the Chef libs and see if I can chase it down.

–tucker

On Sat, Jan 4, 2014 at 3:23 AM, Riccardo Tacconi rtacconi@gmail.com wrote:

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).

–tucker

Same problem here, reproducible in both latest master and tagged 1.0.0 sensu-chef. Also using Vagrant + Chef Solo

Details:

ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]

==> linux: ================================================================================

==> linux: Recipe Compile Error in /tmp/vagrant-chef-2/chef-solo-1/cookbooks/sensu/recipes/default.rb

==> linux: ================================================================================

==> linux:

==> linux:

==> linux: TypeError

==> linux: ---------

==> linux: can’t convert Array into String

==> linux:

==> linux:

==> linux: Cookbook Trace:

==> linux: ---------------

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

==> linux: /tmp/vagrant-chef-2/chef-solo-1/cookbooks/sensu/recipes/default.rb:58:in `from_file’

==> linux:

==> linux:

==> linux: Relevant File Content:

==> linux: ----------------------

==> linux: /tmp/vagrant-chef-2/chef-solo-1/cookbooks/sensu/libraries/sensu_helpers.rb:

==> linux:

==> linux: 29: “/opt/sensu/embedded/bin/gem”

==> linux: 30: else

==> linux: 31: “gem”

==> linux: 32: end

==> linux: 33: end

==> linux: 34:

==> linux: 35: def data_bag_item(item, missing_ok=false)

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

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

==> linux: 38: if value.is_a?(Hash)

==> linux: 39: value.has_key?(“encrypted_data”)

==> linux: 40: end

==> linux: 41: end

==> linux: 42: if encrypted

==> linux: 43: secret = Chef::EncryptedDataBagItem.load_secret

==> linux: 44: Chef::EncryptedDataBagItem.new(raw_hash, secret)

==> linux: 45: else

==> linux:

==> linux:

==> linux:

==> linux: [2014-06-11T16:55:26+01:00] ERROR: Running exception handlers

==> linux: [2014-06-11T16:55:26+01:00] ERROR: Exception handlers complete

==> linux: [2014-06-11T16:55:26+01:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out

==> linux: [2014-06-11T16:55:26+01:00] ERROR: can’t convert Array into String

==> linux: [2014-06-11T16:55:26+01:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Any sane way to work around this problem without having to touch the developer’s ruby version?

···

On Wednesday, 8 January 2014 22:25:06 UTC, Tucker wrote:

Final update:

The problem was a combination of ruby-1.9.3p484 and Chef. Sadly, we’ve hit similar TypeErrors with this Ruby patch level in the past and I forgot. For anyone who comes across this, either use ruby-1.9.3p448 (don’t though, there’s a big security hole with floating points) or use ruby >= 2.0.0p353.

On Mon, Jan 6, 2014 at 6:49 PM, Tucker ju...@gmail.com wrote:

I think I’ve narrowed it down to a problem with Vagrant. Looking through the Vagrant chef_solo provisioner, it appears it should be writing out a string but I’m still getting an array. Unless I come full circle again and can point the blame elsewhere, I’ll let this thread here die.

On Mon, Jan 6, 2014 at 6:26 PM, Tucker ju...@gmail.com wrote:

Digging further down the rabbit hole, I’ve found that it’s something with Chef::Config[:data_bag_path] in chef-XY.Z/lib/chef/data_bag.rb. I’ve checked the code for Chef 10 and Chef 11 and it hasn’t changed, so it’s obviously something wonky on my side. My debug statements have it as [“/tmp/vagrant-chef-1/chef-solo-1/data_bags”], which is obviously an array and not a string. Now I just need to sort out why it’s an array and not a string.

On Sat, Jan 4, 2014 at 11:04 AM, Tucker ju...@gmail.com wrote:

That, I understand. What I have yet to be able to debug is why it’s happening. I’m not sure if this is something in my environment, something in the cookbook or something in the version of Chef I’m using. My Vagrant machine uses ruby-1.9.3 (not sure of patch level right now) and Chef 11.8.2. I’ll try adding some additional debug code to the Chef libs and see if I can chase it down.

On Sat, Jan 4, 2014 at 3:23 AM, Riccardo Tacconi rtac...@gmail.com wrote:

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).

–tucker

–tucker

–tucker

–tucker