mjpete3/x12

Infinite loop when viewing console output

Closed this issue · 8 comments

Wylan commented

After updating the the latest version of the gem we have encountered an issue when trying to parse a document via the console. The console will hang until ctrl+c is pressed. Reverting to the older version seems to resolve the issue.

I believe it is being caused by line 54 in base.rb, commenting out super.inspect seems to resolve the issue, but the output is less legible. The project is using Ruby 2.1.4.

def inspect
   "#{self.class.to_s.sub(/^.*::/, '')} (#{name}) #{repeats} #{super.inspect[1..-2]} =<#{parsed_str}, #{next_repeat.inspect}> ".gsub(/\\*\"/, '"')
end

Wylan,

Have you been able to come up with a better work around instead of commenting out the line?
I haven't had a chance to really look at the issue yet.
Marty

Wylan commented

Hi Marty,

I've been pretty busy so I haven't had a chance to dive deeper into it yet, but hopefully I will this weekend.

Wylan commented

So I had a little more time to look into the issue and it seems that changing

#{next_repeat.inspect}

to

#{next_repeat}

avoids the issue, but again the output is not super legible.

This is very helpful. I'm trying to see if I can free up some time this
weekend to work on the code. In addition to working full time, I'm also
starting up a new business. Time is a premium. The work your putting
in is extremely helpful and appreciated!!

I think this may stem from the newer version of Ruby (although I may be
wrong on that).

Marty

On Tue, 2015-04-14 at 09:25 -0700, Wylan wrote:

So I had a little more time to look into the issue and it seems that
changing

#{next_repeat.inspect}
to

#{next_repeat}
avoids the issue, but again the output is not super legible.


Reply to this email directly or view it on GitHub.

Wylan commented

I'm glad to be able to help, we using the gem in a project at work so I am able to take some time during the day to look into it. I too suspect that the ruby version has something to do with it since we didnt have issues before upgrading to 2.1, although I'm not sure exactly what changed.

I do think I may have found a decent workaround though. It seems that it was looping in loop.rb (hows that for a pun?). If I copy the inspect method into loop.rb, but remove the call to super.inspect it seems to work. Also the output is not missing anything so far as I can tell.

# inspect in loop.rb
def inspect
  "#{self.class.to_s.sub(/^.*::/, '')} (#{name}) #{repeats} =<#{parsed_str}, #{next_repeat.inspect}> ".gsub(/\\*\"/, '"')
end 

# inspect in base.rb

def inspect
  "#{self.class.to_s.sub(/^.*::/, '')} (#{name}) #{repeats} #{super.inspect[1..-2]} =<#{parsed_str}, #{next_repeat.inspect}> ".gsub(/\\*\"/, '"')
end

I had some time this morning to research differences with inspect
between ruby 1.9.3 and 2.0.0. In version 1.9.3, the inspect method
would be overridden with to_s method. In version 2.0.0 this was changed
so to_s wouldn't override inspect and the object would be return instead
of a string. The base class has both inspect and to_s methods.

I think what is happening is from the loop class, the base class inspect
method is called. The super.inspect is returning an object, not a
string. Then inspect is being called on that object.....

Your monkey patch makes sense. I'm going to bring it into code base and
release ver 1.5.1 in a little bit.

Marty

On Wed, 2015-04-15 at 08:49 -0700, Wylan wrote:

I'm glad to be able to help, we using the gem in a project at work so
I am able to take some time during the day to look into it. I too
suspect that the ruby version has something to do with it since we
didnt have issues before upgrading to 2.1, although I'm not sure
exactly what changed.

I do think I may have found a decent workaround though. It seems that
it was looping in loop.rb (hows that for a pun?). If I copy the
inspect method into loop.rb, but remove the call to super.inspect it
seems to work. Also the output is not missing anything so far as I can
tell.

inspect in loop.rb

def inspect
"#{self.class.to_s.sub(/^._::/, '')} (#{name}) #{repeats} =<#{parsed_str}, #{next_repeat.inspect}> ".gsub(/_"/, '"')
end

inspect in base.rb

def inspect
"#{self.class.to_s.sub(/^._::/, '')} (#{name}) #{repeats} #{super.inspect[1..-2]} =<#{parsed_str},
#{next_repeat.inspect}> ".gsub(/_"/, '"')
end

Reply to this email directly or view it on GitHub.

Version 1.5.1 of pd_x12 is available on rubygems.org

On Wed, 2015-04-15 at 08:49 -0700, Wylan wrote:

I'm glad to be able to help, we using the gem in a project at work so
I am able to take some time during the day to look into it. I too
suspect that the ruby version has something to do with it since we
didnt have issues before upgrading to 2.1, although I'm not sure
exactly what changed.

I do think I may have found a decent workaround though. It seems that
it was looping in loop.rb (hows that for a pun?). If I copy the
inspect method into loop.rb, but remove the call to super.inspect it
seems to work. Also the output is not missing anything so far as I can
tell.

inspect in loop.rb

def inspect
"#{self.class.to_s.sub(/^._::/, '')} (#{name}) #{repeats} =<#{parsed_str}, #{next_repeat.inspect}> ".gsub(/_"/, '"')
end

inspect in base.rb

def inspect
"#{self.class.to_s.sub(/^._::/, '')} (#{name}) #{repeats} #{super.inspect[1..-2]} =<#{parsed_str},
#{next_repeat.inspect}> ".gsub(/_"/, '"')
end

Reply to this email directly or view it on GitHub.

Wylan commented

Glad I was able to help, I just updated to 1.5.1 and everything seems to be working as expected.