6 Replies Latest reply on Oct 6, 2014 6:20 AM by Alexey Mironov

    Null array

    Alexey Mironov

      Hello,

       

      some times I have rhoconnect error -

       

      [22067][10:32:50.386 AM 2014-09-22] undefined method `to_array' for nil:NilClass/opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rhoconnect-4.0.4/lib/rhoconnect/controller/clients_controller.rb:60:in `block in <class:ClientsController>'

       

       

      Rhoconnect source clients_controller.rb is:

       

        get "/:client_id", \
                        :deprecated_route => {:verb => :post, :url => ['/api/get_client_params', '/api/client/get_client_params']} do
          Client.load(params[:client_id],{:source_name => '*'}).to_array.to_json
        end

       

      I think it is internal error by Null client_id value reason. Why did it happend?

        • Re: Null array
          Alexey Mironov

          Full stack is:

           

          [22077][10:38:57.272 AM 2014-09-22] undefined method `to_array' for nil:NilClass/opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rhoconnect-4.0.4/lib/rhoconnect/controller/clients_controller.rb:60:in `block in <class:ClientsController>'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rhoconnect-4.0.4/lib/rhoconnect/server.rb:137:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rhoconnect-4.0.4/lib/rhoconnect/server.rb:137:in `block in execute_api_call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rhoconnect-4.0.4/lib/rhoconnect/server.rb:109:in `catch_all'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rhoconnect-4.0.4/lib/rhoconnect/server.rb:131:in `execute_api_call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rhoconnect-4.0.4/lib/rhoconnect/server.rb:280:in `block in api4'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `block in compile!'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `[]'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (3 levels) in route!'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:985:in `route_eval'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (2 levels) in route!'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1006:in `block in process_route'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `catch'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `process_route'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:964:in `block in route!'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `each'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `route!'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1076:in `block in dispatch!'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1073:in `dispatch!'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `block in call!'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `call!'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:886:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rhoconnect-4.0.4/lib/rhoconnect/middleware/current_user.rb:14:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rhoconnect-4.0.4/lib/rhoconnect/middleware/current_app.rb:12:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/async-rack-0.5.1/lib/async_rack/async_callback.rb:114:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/async-rack-0.5.1/lib/async_rack/async_callback.rb:91:in `block in new'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rhoconnect-4.0.4/lib/rhoconnect/middleware/stats.rb:21:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rhoconnect-4.0.4/lib/rhoconnect/middleware/stats.rb:21:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rhoconnect-4.0.4/lib/rhoconnect/middleware/body_content_type_parser.rb:31:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rhoconnect-4.0.4/lib/rhoconnect/middleware/x_domain_session_wrapper.rb:25:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/static.rb:119:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/rhoconnect-4.0.4/lib/rhoconnect/async.rb:51:in `block in call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:1037:in `call'

          /opt/rhoconnect/lib/ruby/gems/1.9.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:1037:in `block in spawn_threadpool'

            • Re: Null array
              Kutir Mobility

              Alexey,

              Could you please trace the scenario of when it is happening or attach your source code to reproduce locally?

               

              Visnupriya R

              Kutir Mobility

                • Re: Null array
                  Alexey Mironov

                  I do not know how dose it happened (what user doing). It was our clients log.... And I do not know what controller hase bin called in this moment. Error stack do not include any of my controller link. May be it was network data transmit error....?

                  Users sads what sync goig soo good and all data was transmited good....

                  I can only add my controller sources if it help -

                   

                  -------------------------------------------------------------------------------------------------------------------------------------------------------------------------

                  client.rb

                   

                  require 'oci8'

                   

                  class Clients < Rhoconnect::Model::Base

                    def initialize(source)

                      puts "Clients Begin SYNC"

                      puts "Date Time: " + Time.now.to_s   

                     

                      f = File.new(Dir.pwd + "/settings/config.txt")

                      i = 0

                      f.each do |line|

                        if (i.to_i == 0)        

                          @tconn = line.chop

                        end 

                        i = i.to_i + 1

                      end

                      f.close 

                     

                      @tclient = OCI8.new(@tconn)

                      @tclient.logoff  

                          

                      super(source)

                    end

                   

                    def login

                    end

                   

                    def query(params=nil)

                      f = File.new(Dir.pwd + "/settings/config.txt")

                      i = 0

                      f.each do |line|

                        if (i.to_i == 0)        

                          @conn = line.chop

                        end 

                        i = i.to_i + 1

                      end

                      f.close 

                     

                      puts "Begin Clients Query"  

                      puts "By User: " + params['device_id'][0,20].to_s

                     

                      @client = OCI8.new(@conn)

                         

                      sql = 'SELECT ID,POINT_ID,POINT_NAME,CL_NAME,ACC_KT,POINT_ADDRESS,INN,ACC_RS,ACC_DT,BANK_BIC,BANK_NAME,SYM,PIN,VBANK_NAME,VBANK_BIC,NAZ_PLAT FROM VW_RPT_VOZ_TCD_POINTS'

                   

                      @result={}

                     

                      @client.exec("BEGIN DBMS_SESSION.SET_CONTEXT('CLIENTCONTEXT', 'TCD', '" +  params['device_id'][0,20].to_s + "'); END;")      

                      @client.commit       

                   

                      i = 0

                      @client.exec(sql) do |row|

                        #puts row 

                       

                        i = i.to_i + 1

                       

                        inventlocation = {}

                        inventlocation["ID"] = row[0].to_i

                   

                        begin

                          inventlocation["POINT_ID"] = row[1].encode('utf-8')

                        rescue

                          inventlocation["POINT_ID"] = ''

                        rescue

                        ensure

                        end

                   

                        begin

                          inventlocation["POINT_NAME"] = row[2].encode('utf-8')

                        rescue

                          inventlocation["POINT_NAME"] = ''

                        ensure

                        end

                   

                        begin

                          inventlocation["CL_NAME"] = row[3].encode('utf-8')

                        rescue

                          inventlocation["CL_NAME"] = ''

                        ensure

                        end

                   

                        begin

                          inventlocation["ACC_KT"] = row[4].encode('utf-8')

                        rescue

                          inventlocation["ACC_KT"] = ''

                        ensure

                        end

                   

                        begin

                          inventlocation["POINT_ADDRESS"] = row[5].encode('utf-8')

                        rescue

                          inventlocation["POINT_ADDRESS"] = ''

                        ensure

                        end

                   

                        begin

                          inventlocation["INN"] = row[6].encode('utf-8')

                        rescue

                          inventlocation["INN"] = ''

                        ensure

                        end

                   

                        begin

                          inventlocation["ACC_RS"] = row[7].encode('utf-8')

                        rescue

                          inventlocation["ACC_RS"] = ''

                        ensure

                        end

                   

                        begin

                          inventlocation["ACC_DT"] = row[8].encode('utf-8')

                        rescue

                          inventlocation["ACC_DT"] = ''

                        ensure

                        end

                   

                        begin

                          inventlocation["BANK_BIC"] = row[9].encode('utf-8')

                        rescue

                          inventlocation["BANK_BIC"] = ''

                        ensure

                        end

                   

                        begin

                          inventlocation["BANK_NAME"] = row[10].encode('utf-8')

                        rescue

                          inventlocation["BANK_NAME"] = ''

                        ensure

                        end

                   

                        begin

                          inventlocation["SYM"] = row[11].encode('utf-8')

                        rescue

                          inventlocation["SYM"] = ''

                        ensure

                        end

                   

                        begin

                          inventlocation["PIN"] = row[12].encode('utf-8')

                        rescue

                          inventlocation["PIN"] = ''

                        ensure

                        end

                   

                        begin

                          inventlocation["VBANK_NAME"] = row[13].encode('utf-8')

                        rescue

                          inventlocation["VBANK_NAME"] = ''

                        ensure

                        end

                   

                        begin

                          inventlocation["VBANK_BIC"] = row[14].encode('utf-8') 

                        rescue

                          inventlocation["VBANK_BIC"] = ''

                        ensure

                        end

                   

                        begin

                          inventlocation["NAZ_PLAT"] = row[15].encode('utf-8')

                        rescue

                          inventlocation["NAZ_PLAT"] = ''

                        ensure

                        end

                                                                      

                        @result[row[0].to_s] = inventlocation                            

                      end     

                   

                      puts "Clients download process ended ok! " + i.to_s + " records download..."   

                     

                      @client.logoff      

                    end

                   

                    def create(create_hash)

                    end

                   

                    def update(update_hash)

                    end

                   

                    def delete(delete_hash)

                    end

                   

                    def logoff

                    end

                   

                    def store_blob(object,field_name,blob)

                    end

                    end

                   

                  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

                  users.rb

                   

                  require 'oci8'

                   

                  class Users < Rhoconnect::Model::Base

                    def initialize(source)

                      puts "Users Begin SYNC"

                      puts "Date Time: " + Time.now.to_s   

                     

                      f = File.new(Dir.pwd + "/settings/config.txt")

                      i = 0

                      f.each do |line|

                        if (i.to_i == 0)        

                          @tconn = line.chop

                        end 

                        i = i.to_i + 1

                      end

                      f.close 

                     

                      @tclient = OCI8.new(@tconn)

                      @tclient.logoff  

                         

                      super(source)

                    end

                   

                    def login

                    end

                   

                    def query(params=nil)

                      f = File.new(Dir.pwd + "/settings/config.txt")

                      i = 0

                      f.each do |line|

                        if (i.to_i == 0)        

                          @conn = line.chop

                        end 

                        i = i.to_i + 1

                      end

                      f.close 

                    

                      puts "Begin Users Query"  

                      puts "By User: " + params['device_id'][0,20].to_s   

                     

                      @client = OCI8.new(@conn.encode('utf-8') )          

                       

                      sql = "SELECT to_number(ID,'999999999999') ID,NAME,PIN FROM VW_RPT_VOZ_TCD_USERS"

                     

                      @result={}

                   

                   

                      @client.exec("BEGIN DBMS_SESSION.SET_CONTEXT('CLIENTCONTEXT', 'TCD', '" +  params['device_id'][0,20].to_s + "'); END;") 

                      @client.commit  

                   

                      i = 0

                     

                      @client.exec(sql) do |row|

                        #puts row

                   

                        i = i.to_i + 1

                       

                        inventlocation = {}

                        inventlocation["ID"] = row[0].to_i

                        inventlocation["NAME"] = row[1].encode('utf-8') 

                      begin

                          inventlocation["PIN"] = row[2].encode('utf-8') 

                        rescue

                          inventlocation["PIN"] = row[2] 

                        ensure

                        end 

                                                                      

                        @result[row[0].to_s] = inventlocation  

                      end      

                      @client.commit

                     

                      puts "Users download process ended ok!"  + i.to_s + " records download..."   

                     

                      @client.logoff   

                    end

                   

                    def create(create_hash)

                    end

                   

                    def update(update_hash)

                      f = File.new(Dir.pwd + "/settings/config.txt")

                      i = 0

                      f.each do |line|

                        if (i.to_i == 0)        

                          @conn = line.chop

                        end 

                        i = i.to_i + 1

                      end

                      f.close 

                   

                      puts "Begin Users's PIN update"      

                      puts "begin Z$VOZ_INK_TCD_USER_L.UPDATE_REC(" + update_hash["id"].to_s + ",'" + update_hash["PIN"].to_s + "'); end;"

                       

                      begin     

                      @client = OCI8.new(@conn)   

                               

                      cursor = @client.parse("begin Z$VOZ_INK_TCD_USER_L.UPDATE_REC(" + update_hash["id"].to_s + ",'" + update_hash["PIN"].to_s + "'); end;")

                       

                      cursor.exec

                       

                      @client.commit

                     

                      puts "User's PIN sucess updated"

                     

                      @client.logoff

                     

                      rescue

                          puts "Error Update PIN: " + "begin Z$VOZ_INK_TCD_USER_L.UPDATE_REC(" + update_hash["id"].to_s + ",'" + update_hash["PIN"].to_s + "'); end;"

                          @client.logoff

                          raise "Error Update PIN: " + "begin Z$VOZ_INK_TCD_USER_L.UPDATE_REC(" + update_hash["id"].to_s + ",'" + update_hash["PIN"].to_s + "'); end;"

                      ensure

                      end          

                    end

                   

                    def delete(delete_hash)

                    end

                   

                    def logoff

                    end

                   

                    def store_blob(object,field_name,blob)

                    end

                  end

                  ---------------------------------------------------------------------------------------------------------------------------------------------------------------------

                   

                  route.rb

                   

                  require 'oci8'

                   

                  class Route < Rhoconnect::Model::Base

                    def initialize(source)

                      puts "Route Begin SYNC"

                      puts "Date Time: " + Time.now.to_s   

                     

                      f = File.new(Dir.pwd + "/settings/config.txt")

                      i = 0

                      f.each do |line|

                        if (i.to_i == 0)        

                          @tconn = line.chop

                        end 

                        i = i.to_i + 1

                      end

                      f.close 

                     

                      @tclient = OCI8.new(@tconn)

                      @tclient.logoff  

                         

                      super(source)

                    end

                   

                    def login

                    end

                   

                    def query(params=nil)

                      @result={} 

                    end

                   

                    def create(create_hash)

                      f = File.new(Dir.pwd + "/settings/config.txt")

                      i = 0

                      f.each do |line|

                        if (i.to_i == 0)        

                          @conn = line.chop

                        end 

                        i = i.to_i + 1

                      end

                      f.close 

                   

                      puts "Route"

                      puts "By User: " + create_hash["device_id"].to_s 

                     

                      begin 

                      @client = OCI8.new(@conn)   

                     

                      @TSD_ID = create_hash["device_id"].to_s

                     

                      @client.exec("BEGIN DBMS_SESSION.SET_CONTEXT('CLIENTCONTEXT', 'TCD', '" +  @TSD_ID + "'); END;") 

                   

                      @client.commit

                        

                   

                      puts "begin  Z$VOZ_INK_DEV_DATA_L.INSERT_REC('" + create_hash["POINT_ID"].to_s + "','" + create_hash["SUMMA"].to_s + "','" + create_hash["BAG_NUM"].to_s + "','" + create_hash["ROUTE"].to_s + "','" + create_hash["NUM_MARCH"].to_s + "','" + create_hash["IN_DATE"].to_s + "','" + create_hash["IN_TIME"].to_s + "','" + create_hash["NOMINALS"].to_s + "','" + create_hash["FLAG"].to_s + "','" + create_hash["INN"].to_s + "','" + create_hash["ACC_RS"].to_s + "','" + create_hash["SYM"].to_s  + "','" + create_hash["USER_ID"].to_s + "'); end;"

                   

                      cursor = @client.parse("begin  Z$VOZ_INK_DEV_DATA_L.INSERT_REC

                      (

                       '" + create_hash["POINT_ID"].to_s + "'

                      ,'" + create_hash["SUMMA"].to_s + "'

                      ,'" + create_hash["BAG_NUM"].to_s + "'

                      ,'" + create_hash["ROUTE"].to_s + "'

                      ,'" + create_hash["NUM_MARCH"].to_s + "'

                      ,'" + create_hash["IN_DATE"].to_s + "'

                      ,'" + create_hash["IN_TIME"].to_s + "'

                      ,'" + create_hash["NOMINALS"].to_s + "'

                      ,'" + create_hash["FLAG"].to_s + "'

                      ,'" + create_hash["INN"].to_s + "'

                      ,'" + create_hash["ACC_RS"].to_s + "'

                    ,'" + create_hash["SYM"].to_s + "'

                      ,'" + create_hash["USER_ID"].to_s + "'

                      ); end;")   

                   

                     # cursor = @client.parse("begin  Z$VOZ_INK_DEV_DATA_L.INSERT_REC('00360','200','2','1','1','04062014','153308','','0','5003052454','','24035865299'); end;")

                   

                      cursor.exec

                     

                      @client.commit

                      @client.logoff  

                   

                      id = create_hash["IN_DATE"].to_s + create_hash["IN_TIME"].to_s + create_hash["BAG_NUM"].to_s

                       

                      id

                             

                      rescue

                        puts "Error INSERT Route: " + "begin  Z$VOZ_INK_DEV_DATA_L.INSERT_REC('" + create_hash["POINT_ID"].to_s + "','" + create_hash["SUMMA"].to_s + "','" + create_hash["BAG_NUM"].to_s + "','" + create_hash["ROUTE"].to_s + "','" + create_hash["NUM_MARCH"].to_s + "','" + create_hash["IN_DATE"].to_s + "','" + create_hash["IN_TIME"].to_s + "','" + create_hash["NOMINALS"].to_s + "','" + create_hash["FLAG"].to_s + "','" + create_hash["INN"].to_s + "','" + create_hash["ACC_RS"].to_s + "','" + create_hash["SYM"].to_s  + "','" + create_hash["USER_ID"].to_s + "'); end;"     

                        @client.logoff

                        raise "Error INSERT Route: " + "begin  Z$VOZ_INK_DEV_DATA_L.INSERT_REC('" + create_hash["POINT_ID"].to_s + "','" + create_hash["SUMMA"].to_s + "','" + create_hash["BAG_NUM"].to_s + "','" + create_hash["ROUTE"].to_s + "','" + create_hash["NUM_MARCH"].to_s + "','" + create_hash["IN_DATE"].to_s + "','" + create_hash["IN_TIME"].to_s + "','" + create_hash["NOMINALS"].to_s + "','" + create_hash["FLAG"].to_s + "','" + create_hash["INN"].to_s + "','" + create_hash["ACC_RS"].to_s + "','" + create_hash["SYM"].to_s  + "','" + create_hash["USER_ID"].to_s + "'); end;"

                       

                        id = create_hash["IN_DATE"].to_s + create_hash["IN_TIME"].to_s + create_hash["BAG_NUM"].to_s

                       

                        id

                      ensure

                      end       

                    end

                   

                    def update(update_hash)

                    end

                   

                    def delete(delete_hash)

                    end

                   

                    def logoff

                    end

                   

                    def store_blob(object,field_name,blob)

                    end

                  end