parslet
parslet copied to clipboard
Error during inspect: undefined local variable or method 'root'
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.
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.
Good catch. I'll work on this as soon as I get around to it. Thank you for the report!