I need help understanding some code..

Discussion in 'Ruby' started by Thomas Foster, Mar 5, 2014.

  1. I am new to ruby, but have been writing some code to understand it better. I am writing this post because I need some help with determining where SystemStackError is located...I am trying to use a ruby library to automate building vms in vmware an I see this error everytime I run the code.

    /usr/local/rvm/gems/ruby-1.9.3 p545/gems/fog-.20.0/lib/fog/core/collection.rb stack level too deep (SystemStackError)


    Here is the line that generates the error and I am trying to see if I can resolve this problem (with the help of you guys). I appreciate any help..Hopefully you can point me in the right direction so I can try and fix this problem.

    def inspect
    Thread.current[:formatador] ||= Formatador.new
    data = "#{Thread.current[:formatador].indentation}<#{self.class.name}\n"
    Thread.current[:formatador].indent do
    unless self.class.attributes.empty?
    data << "#{Thread.current[:formatador].indentation}"
    data << self.class.attributes.map {|attribute| "#{attribute}=#{send(attribute).inspect}"}.join(",\n#{Thread.current[:formatador].indentation}")
    data << "\n"
    end
    data << "#{Thread.current[:formatador].indentation}["
    unless self.empty?
    data << "\n"
    Thread.current[:formatador].indent do
    data << self.map {|member| member.inspect}.join(",\n")
    data << "\n"
    end
    data << Thread.current[:formatador].indentation
    end
    data << "]\n"
    end
    data << "#{Thread.current[:formatador].indentation}>"
    data
    end


    If you need more info, please let me know.
     
    Thomas Foster, Mar 5, 2014
    #1
    1. Advertisements



  2. I am running ruby 1.9.3 with rbvmomi 1.6.0 and fog 1.20
     
    Thomas Foster, Mar 5, 2014
    #2
    1. Advertisements



  3. After reading a few posts around the google machine..I think I found the issue was with the inspect function and the existing inspect method implemented in ruby...When I changed the def inspect line to def inspects..the issuewas resolved..I don't know what else it broke :) but I am able to access my objects in VSphere 5.1.
     
    Thomas Foster, Mar 5, 2014
    #3
  4. But that is a different method - #inspect is invoked at specific places
    (e.g. from method "p") and if you change the name that won't happen.

    I do not know the data structure that you are printing there but if you
    have circular dependencies that might explain the issue you are seeing.
    The error you reported was really what happens on recursion which is
    not terminated before it runs out of stack space:

    irb(main):011:0> def f;f; end
    => nil
    irb(main):012:0> f
    SystemStackError: stack level too deep
    from /usr/lib/ruby/1.9.1/irb/workspace.rb:80

    Cheers

    robert
     
    Robert Klemme, Mar 7, 2014
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.