[jruby-user] Getting full-full stack traces of Java exceptions

148 views
Skip to first unread message

Trejkaz

unread,
Jan 24, 2013, 10:24:35 PM1/24/13
to us...@jruby.codehaus.org
Hi all.

I'm using rspec to test an API which we support as Ruby but which is
written in Java. When a failure occurs, I get a backtrace like this:

A problem occurred (Java::Acme::LicenceException)
Java::Acme::LicenceException:
A problem occurred
com.acme.Widget.initialise(Widget.java:80)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(JavaMethod.java:440)
[... cutting the rest for brevity in email ...]

The real cause for the exception which I would like to read is in the
Java exception's cause... which normally would be on the stack trace,
but isn't. The suppressed exceptions might be useful too, of course...

I have tried adding -d to the JRuby command and --backtrace to the
rspec command, but neither of these appear to change the behaviour.

Is there any way to get this?

TX


P.S. Here's how I'm actually running it all, in case that matters:

<java fork="yes" classname="org.jruby.Main" failonerror="false">
<classpath refid="run-classpath" />
<env key="CI_REPORTS" value="@{reportdir}" />

<arg value="-d"/> <!-- seems to make no difference -->

<arg line="-S rspec"/>
<arg value="src/test/rspec"/> <!-- Path to root specs dir -->

<arg value="--backtrace"/> <!-- seems to make no difference -->

<arg line="--require ci/reporter/rake/rspec_loader"/>
<arg line="--format CI::Reporter::RSpecDoc"/>
<arg line="--format html --out"/> <arg value="@{reportdir}/specs.html"/>
</java>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Roger Pack

unread,
Feb 2, 2013, 6:05:16 PM2/2/13
to us...@jruby.codehaus.org
try jruby -h there may be some parameter...

--
Posted via http://www.ruby-forum.com/.

Trejkaz

unread,
May 7, 2013, 3:01:47 AM5/7/13
to us...@jruby.codehaus.org
On Sun, Feb 3, 2013 at 10:05 AM, Roger Pack <li...@ruby-forum.com> wrote:
> try jruby -h there may be some parameter...

Not as far as I can tell (the fact that I mentioned already using a
JRuby parameter to try and get this to happen may hint to some that I
had already looked through the docs.)

I was hoping that there would be a hidden switch somewhere to make
Java exceptions suck less when output by Ruby...

TX

Lenny Marks

unread,
May 7, 2013, 1:31:58 PM5/7/13
to us...@jruby.codehaus.org

On May 7, 2013, at 3:01 AM, Trejkaz wrote:

> On Sun, Feb 3, 2013 at 10:05 AM, Roger Pack <li...@ruby-forum.com> wrote:
>> try jruby -h there may be some parameter...
>
> Not as far as I can tell (the fact that I mentioned already using a
> JRuby parameter to try and get this to happen may hint to some that I
> had already looked through the docs.)
>
> I was hoping that there would be a hidden switch somewhere to make
> Java exceptions suck less when output by Ruby…

I created a log4jruby gem some time ago which we've been using successfully for quite some time. It handles exception unraveling.

e.g. # this would log the error message and the full stack trace
rescue => e
logger.error(e)
..

I'm not aware of anything built in. You can probably lift some code from log4jruby if not use it directly.

https://github.com/lenny/log4jruby

-lenny

Trejkaz

unread,
Jun 17, 2013, 9:58:35 PM6/17/13
to us...@jruby.codehaus.org
On Wed, May 8, 2013 at 3:31 AM, Lenny Marks <le...@aps.org> wrote:
> I created a log4jruby gem some time ago which we've been using successfully for quite
> some time. It handles exception unraveling.

The code for unraveling the exceptions is quite handy. What I'm having
issues with now is figuring out what to monkeypatch in rspec to make
it use it...

We're using CI::Reporter as well, so I had hoped that it would have a
nice intercept point for it. I found one which looked right so I
redefined that method, but sadly, it isn't calling any of my code...
Reply all
Reply to author
Forward
0 new messages