Problem with class initialize


#1

We have a problem with the initialization of a class and we don’t understand the error and especially how to debug this situation.

# encoding: UTF-8
#
# Description: retrieve configuration data from the configuration domain or source of truth and store it in cache
**# **
# Howto Call:
# Common::Library::RetrieveConfiguration.new.config
**# **
# Howto Clear Cache and get new Data
# Common::Library::RetrieveConfiguration.new.reload_config
#

@debug = true

require ‘dalli’

module Common
module Library
class RetrieveConfiguration
attr_reader :config
def initialize(handle = $evm)
@handle.log(:info, “sot_file_name:}”)
@handle = handle
@sot_file_name = @handle.root[‘dialog_sot_file_name’]
@handle.log(:info, “sot_file_name: #{@handle.root[‘dialog_sot_file_name’]}”)
@sot_branch_name = get_sot_branch_name
@config_key = @sot_file_name
@cache = Dalli::Client.new(nil, namespace: ‘ESA’, expires_in: 60.seconds)
@handle.log(:info, “result:2 cache: #{@cache}”) if @debug
load_config
end

  def reload_config()
    invalidate
    load_config
    @config
  end

  private
  def load_config()
    @config = @cache.get(@config_key)
    if @config.nil?
      @config = {}
      @handle.log(:info, "result:3 config: #{@config}")
      #@config = YAML.load(File.read("/mnt/sot/#{@sot_file_name}"))
      @config = YAML.load(Common::Library::Bitbucket::bitbucket_rest(:get, "raw/active/#{@sot_file_name}?at=#{@sot_branch_name}", nil))
      @handle.log(:info, "result:4 config: #{@config}")
      @cache.set(@config_key, @config)
      @handle.log(:info, "result:5 config: #{@cache}")
      @handle.log(:info, "Configuration loaded from sot")
    else
      @handle.log(:info, "Configuration loaded from memcache")
    end   
  end

  def invalidate()
    @cache.delete(@config_key)
  end
end

end
end`

from a method we call our class:
sot = Common::Library::RetrieveConfiguration.new.config

image

in the logs, we have this error that recurs with each call:
[----] E, [2018-12-18T08:05:27.666379 #2109:fd2848] ERROR – : <AEMethod get_param_from_sot_list> The following error occurred during method evaluation:

[----] E, [2018-12-18T08:05:27.673247 #2109:fd2848] ERROR – : <AEMethod get_param_from_sot_list> NoMethodError: undefined method `log’ for nil:NilClass
Did you mean? load

[----] I, [2018-12-18T08:05:27.676035 #2109:3fc89e4] INFO – : Updated namespace [Dialogs/SourceOfTruth/get_param_from_sot_text test/Dialogs]

[----] E, [2018-12-18T08:05:27.677705 #2109:fd2848] ERROR – : <AEMethod get_param_from_sot_list> test /Common/Library/RetrieveConfiguration:23:in `initialize’

/ test /Dialogs/SourceOfTruth/get_param_from_sot_list:23:in `new’

[----] I, [2018-12-18T08:05:27.692556 #2109:3fc89e4] INFO – : Invoking [inline] method [/test /Dialogs/SourceOfTruth/get_param_from_sot_text] with inputs [{}]

[----] I, [2018-12-18T08:05:27.709628 #2109:3fc89e4] INFO – : Updated namespace [Common/Library/Bitbucket tests/Common]

[----] E, [2018-12-18T08:05:27.722585 #2109:fd2848] ERROR – : Method STDERR: test /Common/Library/RetrieveConfiguration:23:in initialize': undefined methodlog’ for nil:NilClass (NoMethodError)

[----] E, [2018-12-18T08:05:27.731954 #2109:fd2848] ERROR – : Method STDERR: Did you mean? load

[----] I, [2018-12-18T08:05:27.738084 #2109:3fc89e4] INFO – : Loading embedded method test /Common/Library/Bitbucket

[----] E, [2018-12-18T08:05:27.741954 #2109:fd2848] ERROR – : Method STDERR: from / test /Dialogs/SourceOfTruth/get_param_from_sot_list:23:in `new’

[----] I, [2018-12-18T08:05:27.743009 #2109:3fc89e4] INFO – : Updated namespace [Common/Library/RetrieveConfiguration test /Common]

[----] I, [2018-12-18T08:05:27.753487 #2109:3fc89e4] INFO – : Loading embedded method test/Common/Library/RetrieveConfiguration

[----] I, [2018-12-18T08:05:27.754939 #2109:3fc89e4] INFO – : <AEMethod [/test /Dialogs/SourceOfTruth/get_param_from_sot_text]> Starting

[----] E, [2018-12-18T08:05:27.765609 #2109:fd2848] ERROR – : Method STDERR: from / test /Dialogs/SourceOfTruth/get_param_from_sot_list:23:in `<main>’

[----] I, [2018-12-18T08:05:27.783873 #2109:3fc8ea8] INFO – : <AEMethod [/test /Dialogs/SourceOfTruth/get_param_from_sot_list]> Ending

[----] E, [2018-12-18T08:05:27.787147 #2109:3fc8ea8] ERROR – : Aborting instantiation (unknown method return code) betester_phone=&dialog_dialog_sot_folder=active&dialog_param_cf_business_unit=Unit%C3%A9%20d%27affaires%20non%20s%C3%A9l

ectionn%C3%A9&dialog_param_cf_cost_center=12345&dialog_sot_file_name=F5_VS_BRUNO2-TESTS_DEV_https_virtual.yml&dialog_use_case=F5_VS&object_name=f5_vs_cf_ltm_monitor_recv&vmdb_object_type=service_template]

[----] E, [2018-12-18T08:05:26.893197 #2109:aee6d44] ERROR – : <AEMethod get_param_from_sot_list> test /Common/Library/RetrieveConfiguration:23:in `initialize’

/test/Dialogs/SourceOfTruth/get_param_from_sot_list:23:in `new’