oracle / truffleruby

A high performance implementation of the Ruby programming language, built on GraalVM.
https://www.graalvm.org/ruby/
Other
3.02k stars 185 forks source link

Change RegexpError exception message to match CRuby #3398

Closed postmodern closed 4 months ago

postmodern commented 9 months ago

I noticed that Regexp.new(...) raises a slightly different RegexpError exception message when it cannot parse the regular expression. This causes certain tests that check the exception message to fail when ran under TruffleRuby.

Steps To Reproduce

Regexp.new('[abc')

CRuby

premature end of char-class: /[abc/ (RegexpError)

TruffleRuby

premature end of char-class (org.joni.exception.SyntaxException): /[abc/ (RegexpError)

Version Information

eregon commented 9 months ago

IMO a gem/app should not test for this exact exception message, this message is subject to change, even in CRuby. An easy fix/workaround for that would be to test for message.include? 'premature end of char-class'

Probably we should not include the Java exception class there, OTOH I'm pretty sure it could be useful or clearer in some cases e.g. if an ArrayIndexOutOfBoundsException or so happens inside Joni (IIRC that already happened).

postmodern commented 9 months ago

@eregon I discovered this divergent behavior when some of my code re-raised a RegexpError as an OptionParser::InvalidArgument exception. RSpec also insists on testing both the exception class and the exception message. I could have defined a clever regex to match both CRuby's and TruffleRuby's RegexpError exception message, but the TruffleRuby specific information about the Java class appears directly in the middle of the exception message; plus the goal is to avoid adding TruffleRuby/Java specific logic. Feel free to send me a better PR, or change the RegexpError message to not include the Java class name. https://github.com/ronin-rb/ronin/blob/3fe7602913b54a5d0a592d4a95b32a50d48b1375/spec/cli/commands/dns_proxy_spec.rb#L127-L136

andrykonchin commented 4 months ago

Fixed in 7d3feadef32d7c24028a01ed8868ddd01a1ae857.