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
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…
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.
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.