Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clean Stack Traces in Groovy using Eclipse?

Tags:

java

groovy

I am using Groovy in a Java Swing application as part of my plan to force-feed myself dynamic languages until I like them (which is happening, partly).

My stack traces are filled with Groovy stuff like

org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor

is there a way to get Eclipse to remove all of that codehaus stuff (filter stack traces, basically)?

Edit: I can do this from the command-line with grep (well, not yet) so it's not so bad, but inside of Eclipse would be great too.

like image 825
Dan Rosenstark Avatar asked Feb 25 '10 12:02

Dan Rosenstark


2 Answers

There is a Utility in Groovy that does exactly what you want: StackTraceUtils. STU will clean all the callsite information from your stacktrace, leaving the stuff you're really interested in.

Edit: In Java you will have to encasulate the exception in a java.lang.RuntimeExceptionaccording to comments.

Example of usage:

try {
    1/0;
} catch (Throwable t) {
    throw new RuntimeException(org.codehaus.groovy.runtime.StackTraceUtils.sanitize(t)); //Modifies the Throwable and rethrows
}

StackTraceUtils is available in the latest version of Groovy and originally comes from Grails. I'm not sure how you would go about applying this to all of your projects stacktraces but I think both Griffon and Grails does it so there should be some hints in those projects.

like image 119
xlson Avatar answered Oct 18 '22 09:10

xlson


I don't have an answer for "Run as Groovy application", but if you run GroovyTestcases as jUnit tests in Eclipse, there is a "filter stack traces" button above the stack trace view.

like image 2
slim Avatar answered Oct 18 '22 11:10

slim