Forum: JRuby Getting full-full stack traces of Java exceptions

42b570f6f4312a872c2fc671e3ddc82b?d=identicon&s=25 Trejkaz Xx (trejkaz)
on 2013-01-25 04:26
(Received via mailing list)
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>
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2013-02-03 00:05
try jruby -h there may be some parameter...
42b570f6f4312a872c2fc671e3ddc82b?d=identicon&s=25 Trejkaz Xx (trejkaz)
on 2013-05-07 09:03
(Received via mailing list)
On Sun, Feb 3, 2013 at 10:05 AM, Roger Pack <lists@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
54568ee7ba0c78a836e84c8756a3d681?d=identicon&s=25 Lenny Marks (Guest)
on 2013-05-07 19:34
(Received via mailing list)
On May 7, 2013, at 3:01 AM, Trejkaz wrote:

> On Sun, Feb 3, 2013 at 10:05 AM, Roger Pack <lists@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
42b570f6f4312a872c2fc671e3ddc82b?d=identicon&s=25 Trejkaz Xx (trejkaz)
on 2013-06-18 04:00
(Received via mailing list)
On Wed, May 8, 2013 at 3:31 AM, Lenny Marks <lenny@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...

TX
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.