History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRUBY-2749
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Charles Oliver Nutter
Reporter: Trejkaz
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
JRuby

Make RaiseException show the exception message and the Ruby stack trace

Created: 03/Jul/08 11:47 PM   Updated: 13/Aug/08 11:01 PM
Component/s: Java Integration
Affects Version/s: JRuby 1.1.2
Fix Version/s: JRuby 1.1.4

Time Tracking:
Not Specified


 Description  « Hide
When we get a RaiseException from Java, the output doesn't include any useful information for determining what went wrong.

The bare minimum is to have the original message in the exception including the line number. But also very useful is the stack trace, mainly as it includes line numbers.

JRUBY-506 originally reported this and allegedly the patch was applied, but looking at RaiseException in 1.1.2 it doesn't seem to have been applied.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Trejkaz - 04/Jul/08 12:20 AM
Okay I just noticed the stack trace comes out with printStackTrace()... this is probably okay.

Message from toString() is still missing for me though. It could be that we're doing something wrong.


Charles Oliver Nutter - 04/Jul/08 12:09 PM
No, you're probably just fine. I'm guessing that toString for NativeException does not do the message right. Shouldn't be hard to fix. Can you come up with a simple test case?

Trejkaz - 07/Jul/08 06:43 PM
Okay, I think I have figured out what's going on.

We're running it via JSR223 but actually the problem is more general.

Trivial example via the JSR223 script engine:

public void testJRubyError() throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); manager.getEngineByExtension("rb").eval("raise 'Test'"); }

Outputs:

javax.script.ScriptException: org.jruby.exceptions.RaiseException
at com.sun.script.jruby.JRubyScriptEngine.evalNode(JRubyScriptEngine.java:456)
[cutting rest as script engine stack trace is irrelevant]
Caused by: org.jruby.exceptions.RaiseException

So certainly when being printed as a nested exception nothing is showing. But while playing around with other stuff I discovered that it did somewhat work doing it directly:

public void testJRubyError() throws Throwable {
ScriptEngineManager manager = new ScriptEngineManager();
try { manager.getEngineByExtension("rb").eval("raise 'Test'"); } catch (ScriptException e) { throw e.getCause(); }
}

Output:
org.jruby.exceptions.RaiseException
<unknown>:1: Test (RuntimeError)
...internal jruby stack elided...
...internal jruby stack elided...

My intuition says that whereas printStackTrace() has been overridden in RaiseException, this is not what the outer method is calling (I'm guess it's calling getStackTrace() itself... and I bet overriding that is a more foolproof solution than overriding printStackTrace() anyway.)

The ideal output as I see it would be something like:

javax.script.ScriptException: org.jruby.exceptions.RaiseException
at com.sun.script.jruby.JRubyScriptEngine.evalNode(JRubyScriptEngine.java:456)
[cutting rest as script engine stack trace is irrelevant]
Caused by: org.jruby.exceptions.RaiseException: Test
<unknown>:1: Test (RuntimeError)
...internal jruby stack elided...
...internal jruby stack elided...

Although overriding only getStackTrace() will probably result in getting output closer to what Sun output for Java exceptions.


Charles Oliver Nutter - 13/Aug/08 11:01 PM
I just fixed this in r7457. RaiseException's Java stack trace will now show the Ruby trace information, which means that wrappers like the JSR223 ScriptException should show that trace. And of course you can access it via getCause().getStackTrace().