Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change RegexpError exception message to match CRuby #3398

Open
postmodern opened this issue Jan 21, 2024 · 2 comments
Open

Change RegexpError exception message to match CRuby #3398

postmodern opened this issue Jan 21, 2024 · 2 comments

Comments

@postmodern
Copy link

postmodern commented Jan 21, 2024

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

  • ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
  • truffleruby 23.1.2, like ruby 3.2.2, Oracle GraalVM Native [x86_64-linux]
@eregon
Copy link
Member

eregon commented Jan 22, 2024

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
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants