rubysolo/dentaku

parse error does not show the function causing the error

Nghi93 opened this issue · 0 comments

calculator = Dentaku::Calculator.new
calculator.add_function(:custom, :integer, lambda do
  1
end)

calculator.ast("CUSTOM(1,2)") #=> Dentaku::ParseError (Dentaku::AST::Function::Custom has too many operands)
calculator.ast("CUSTOM(1,2)") #=> Dentaku::ParseError (Dentaku::AST::Function::Custom has too many operands)

calculator = Dentaku::Calculator.new
calculator.add_function(:custom, :integer, lambda do
  1
end)

calculator.ast("CUSTOM(1,2)") #=> Dentaku::ParseError (#<Class:0x00007fbc1a57ecb0> has too many operands)

Probably some caching issue? The method class is not shown but instead an anonymous class.
One quick fix would be to change the fail! method but I think that's not the root cause:

    def fail!(reason, **meta)
      message =
        case reason
          ....
        when :too_many_operands
          "#{meta.fetch(:operator).name} has too many operands"