Project

General

Profile

Actions

Bug #14987

open

foreman_chef-0.3.1 fact_importer failed with IndexError: string not matched

Added by Sebastian Lehn about 8 years ago. Updated almost 8 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
foreman_chef
Target version:
-
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

Facts import failed with following message:

2016-05-10T17:32:29 [app] [W] Action failed
 | IndexError: string not matched
 | /usr/share/foreman/vendor/ruby/2.1.0/gems/foreman_chef-0.3.1/app/models/forema
n_chef/fact_importer.rb:125:in `[]='
 | /usr/share/foreman/vendor/ruby/2.1.0/gems/foreman_chef-0.3.1/app/models/forema
n_chef/fact_importer.rb:125:in `block in unsparse'
 | /usr/share/foreman/vendor/ruby/2.1.0/gems/foreman_chef-0.3.1/app/models/forema
n_chef/fact_importer.rb:121:in `each'
 | /usr/share/foreman/vendor/ruby/2.1.0/gems/foreman_chef-0.3.1/app/models/forema
n_chef/fact_importer.rb:121:in `unsparse'
 | /usr/share/foreman/vendor/ruby/2.1.0/gems/foreman_chef-0.3.1/app/models/forema
n_chef/fact_importer.rb:27:in `add_new_facts'

After altering fact_importer.rb with (added logging):

    class Sparser
      def sparse(hash, options={})
        hash.map do |k, v|
          prefix = (options.fetch(:prefix, [])+[k])
          next sparse(v, options.merge(:prefix => prefix)) if v.is_a? Hash
          { prefix.join(options.fetch(:separator, FactName::SEPARATOR)) => v }
        end.reduce(:merge) || Hash.new
      end

      def logger
        Foreman::Logging.logger('foreman_chef')
      end

      def unsparse(hash, options={})
        ret = Hash.new
        sparse(hash).each do |k, v|
          current            = ret
          key                = k.to_s.split(options.fetch(:separator, FactName::SEPARATOR))
          current            = (current[key.shift] ||= Hash.new) until (key.size<=1)
          begin
                current[key.first] = v
          rescue IndexError
                logger.warn("IndexError occured")
          end
        end
        return ret
      end
    end

i got:


2016-05-10T17:43:02 [foreman_chef] [W] IndexError occured
2016-05-10T17:43:02 [foreman_chef] [W] IndexError occured
2016-05-10T17:43:02 [foreman_chef] [W] IndexError occured
2016-05-10T17:43:02 [foreman_chef] [W] IndexError occured
2016-05-10T17:43:57 [foreman_chef] [I] Import facts for...

My workaround with rescue was useful to me, because i got some of my facts reported which is better than nothing ;-)

Actions

Also available in: Atom PDF