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

Improve JSR-223 exception messages #6591

Merged
merged 2 commits into from Mar 4, 2021
Merged

Conversation

headius
Copy link
Member

@headius headius commented Mar 3, 2021

Basically just adding the topmost Ruby frame's file and line to the message, to match e.g. Jython.

Existing tests do not seem to supply a filename for the top script, so I can only confirm the nameless version of this message is working:

[INFO] Running org.jruby.embed.jsr223.JRubyEngineTest
javax.script.ScriptException: Error during evaluation of Ruby at <script> at 2: (RuntimeError) hello from ruby

Fixes #6560

@headius headius added this to the JRuby 9.3.0.0 milestone Mar 3, 2021
@headius
Copy link
Member Author

headius commented Mar 3, 2021

Dummy test to just print the exception... hoping for more tests that exercise this better...

diff --git a/core/src/test/java/org/jruby/embed/jsr223/JRubyEngineTest.java b/core/src/test/java/org/jruby/embed/jsr223/JRubyEngineTest.java
index 81202a22e6..0f6790321b 100644
--- a/core/src/test/java/org/jruby/embed/jsr223/JRubyEngineTest.java
+++ b/core/src/test/java/org/jruby/embed/jsr223/JRubyEngineTest.java
@@ -619,6 +619,22 @@ public class JRubyEngineTest extends BaseTest {
         }
     }
 
+    /**
+     * Test of invokeMethod method throwing an exception with a null message.
+     */
+    @Test
+    public void testInvokeMethodWithRubyException() throws Exception {
+        ScriptEngine instance = newScriptEngine();
+        instance.eval("def trigger_raise\nraise 'hello from ruby'\nend");
+        try {
+            ((Invocable) instance).invokeMethod(Object.class,"trigger_raise", null);
+            fail("Expected javax.script.ScriptException");
+        } catch (javax.script.ScriptException sex) {
+            sex.printStackTrace();
+            // javax.script.ScriptException is expected
+        }
+    }
+
     /**
      * Test of invokeFunction method, of class Jsr223JRubyEngine.
      */

@headius headius merged commit f91fc8b into jruby:master Mar 4, 2021
@headius headius deleted the better_223_messages branch March 4, 2021 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JRuby should provide the line number of errors when executing in the JSR223 Context
1 participant