kschiess / parslet

A small PEG based parser library. See the Hacking page in the Wiki as well.
kschiess.github.com/parslet
MIT License
809 stars 95 forks source link

Error during inspect: undefined local variable or method 'root' #193

Open Phrogz opened 6 years ago

Phrogz commented 6 years ago

I have a web app using my Flooph gem, which is a class inheriting from Parslet::Parser. When I get certain web app errors, it tries to inspect my class, resulting in a new error (that masks my web app's error). Here's a simple repro:

phrogz$ ruby -e "require 'flooph'; p Flooph.new"
Traceback (most recent call last):
    4: from -e:1:in `<main>'
    3: from -e:1:in `p'
    2: from /Users/phrogz/.rvm/gems/ruby-2.5.1/gems/parslet-1.8.2/lib/parslet/atoms/base.rb:148:in `inspect'
    1: from /Users/phrogz/.rvm/gems/ruby-2.5.1/gems/parslet-1.8.2/lib/parslet/atoms/base.rb:140:in `to_s'
/Users/phrogz/.rvm/gems/ruby-2.5.1/gems/parslet-1.8.2/lib/parslet/parser.rb:66:in `to_s_inner': undefined local variable or method `root' for #<Flooph:0x00007fd635845770> (NameError)

This happens because my class does not define a root rule before it gets inspected.

Phrogz commented 6 years ago

Since I've just patched my gem to avoid this bug, the simpler repro is:
ruby -e "require 'parslet'; p Parslet::Parser.new" …but it will happen when trying to inspect any parser that doesn't have a root rule.

kschiess commented 6 years ago

Good catch. I'll work on this as soon as I get around to it. Thank you for the report!