Issue Details (XML | Word | Printable)

Key: GROOVY-2132
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Jason Dillon
Reporter: Guillaume Laforge
Votes: 1
Watchers: 0
Operations

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

Filter stacktraces in the new shell

Created: 21/Sep/07 04:43 AM   Updated: 01/Oct/07 03:19 AM   Resolved: 01/Oct/07 03:03 AM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: 1.1-rc-1

Time Tracking:
Issue & Sub-Tasks
Issue Only
Not Specified

  • Sub-Tasks:
  • All
  • Open

 Description  « Hide

When things trigger some exceptions, those stacktraces should be filtered to just show the interesting bits to the user:

C:\Documents and Settings\Guillaume Laforge>groovysh
Groovy Shell (1.1-beta-3, JVM: 1.6.0_02-b06)
Type 'help' or '\h' for help.
-------------------------------------------------------------------------------------------------------------
groovy0):000> random()
001> random()
ERROR groovy.lang.MissingMethodException: No signature of method: groovysh_evaluate.random() is applicable for
argument types: () values: {}
at groovy.lang.MetaClassImpl.invokeMissingMethod (MetaClassImpl.java:574)
at groovy.lang.MetaClassImpl.invokeMissingMethod (MetaClassImpl.java:545)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:787)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:614)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:537)
at groovy.lang.GroovyObjectSupport.invokeMethod (GroovyObjectSupport.java:44)
at groovy.lang.Script.invokeMethod (Script.java:78)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN (ScriptBytecodeAdapter.jav
a:71)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrent0 (ScriptBytecodeAdapter.jav
a:99)
at groovysh_evaluate.run (groovysh_evaluate)
...
groovy0):000>

In this example, reducing it to that would be great:

C:\Documents and Settings\Guillaume Laforge>groovysh
Groovy Shell (1.1-beta-3, JVM: 1.6.0_02-b06)
Type 'help' or '\h' for help.
-------------------------------------------------------------------------------------------------------------
groovy0):000> random()
001> random()
ERROR groovy.lang.MissingMethodException: No signature of method: groovysh_evaluate.random() is applicable for
argument types: () values: {}
...
groovy0):000>



Guillaume Laforge added a comment - 21/Sep/07 04:46 AM

Another example with the bug on static imports, the stacktrace is immensly huge and unfriendly:

C:\Documents and Settings\Guillaume Laforge>groovysh
Groovy Shell (1.1-beta-3, JVM: 1.6.0_02-b06)
Type 'help' or '\h' for help.
-------------------------------------------------------------------------------------------------------------
groovy0):000> import static java.lang.Math.*
groovy0):000> random()
001> random()
===> 0.35025511331429426
groovy0):000> c = { random() }
001> c = { random() }
ERROR groovy.lang.MissingMethodException: No signature of method: groovysh_evaluate.random() is applicable for
argument types: () values: {}
at groovy.lang.MetaClassImpl.invokeMissingMethod (MetaClassImpl.java:574)
at groovy.lang.MetaClassImpl.invokeMissingMethod (MetaClassImpl.java:545)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:787)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:614)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:537)
at groovy.lang.GroovyObjectSupport.invokeMethod (GroovyObjectSupport.java:44)
at groovy.lang.Script.invokeMethod (Script.java:78)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeOnDelegationObjects (ClosureMetaClass.
java:326)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod (ClosureMetaClass.java:287)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN (ScriptBytecodeAdapter.jav
a:66)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrent0 (ScriptBytecodeAdapter.jav
a:99)
at groovysh_evaluate$_run_closure1.doCall (groovysh_evaluate:2)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke (Method.java:597)
at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke (ReflectionMetaMethod.java:64)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke (MetaClassHelper.java:537)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod (ClosureMetaClass.java:224)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:614)
at groovy.lang.Closure.call (Closure.java:292)
at groovy.lang.GString.writeTo (GString.java:155)
at groovy.lang.GString.toString (GString.java:133)
at org.codehaus.groovy.reflection.CachedClass.coerceGString (CachedClass.java:95)
at org.codehaus.groovy.reflection.ParameterTypes.coerceArgumentsToClasses (ParameterTypes.java:92)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke (MetaClassHelper.java:535)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:772)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:614)
at org.codehaus.groovy.runtime.Invoker.invokePojoMethod (Invoker.java:87)
at org.codehaus.groovy.runtime.Invoker.invokeMethod (Invoker.java:75)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod (InvokerHelper.java:74)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN (ScriptBytecodeAdapter.java:158)
at org.codehaus.groovy.tools.shell.Groovysh.setLastResult (Groovysh.groovy:92)
at org.codehaus.groovy.tools.shell.Groovysh.this$3$setLastResult (Groovysh.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke (Method.java:597)
at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke (ReflectionMetaMethod.java:64)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke (MetaClassHelper.java:537)
at groovy.lang.MetaClassImpl.setProperty (MetaClassImpl.java:1764)
at groovy.lang.MetaClassImpl.setProperty (MetaClassImpl.java:2412)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke (Method.java:597)
at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke (ReflectionMetaMethod.java:64)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke (MetaClassHelper.java:537)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:772)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:614)
at org.codehaus.groovy.runtime.Invoker.invokePojoMethod (Invoker.java:87)
at org.codehaus.groovy.runtime.Invoker.invokeMethod (Invoker.java:75)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod (InvokerHelper.java:74)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN (ScriptBytecodeAdapter.java:158)
at org.codehaus.groovy.tools.shell.Shell.setProperty (Shell.groovy)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setGroovyObjectProperty (ScriptBytecodeAdapter.ja
va:571)
at org.codehaus.groovy.tools.shell.Groovysh.execute (Groovysh.groovy:182)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke (Method.java:597)
at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke (ReflectionMetaMethod.java:64)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke (MetaClassHelper.java:537)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:772)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN (ScriptBytecodeAdapter.jav
a:66)
at org.codehaus.groovy.tools.shell.Shell.leftShift (Shell.groovy:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke (Method.java:597)
at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke (ReflectionMetaMethod.java:64)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke (MetaClassHelper.java:537)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:772)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:614)
at org.codehaus.groovy.runtime.Invoker.invokePogoMethod (Invoker.java:98)
at org.codehaus.groovy.runtime.Invoker.invokeMethod (Invoker.java:79)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod (InvokerHelper.java:74)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN (ScriptBytecodeAdapter.java:158)
at org.codehaus.groovy.tools.shell.ShellRunner.work (ShellRunner.groovy:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke (Method.java:597)
at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke (ReflectionMetaMethod.java:64)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke (MetaClassHelper.java:537)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:772)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN (ScriptBytecodeAdapter.jav
a:66)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrent0 (ScriptBytecodeAdapter.jav
a:99)
at org.codehaus.groovy.tools.shell.ShellRunner.run (ShellRunner.groovy:57)
at org.codehaus.groovy.tools.shell.InteractiveShellRunner.super$2$run (InteractiveShellRunner.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke (Method.java:597)
at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke (ReflectionMetaMethod.java:64)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke (MetaClassHelper.java:537)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:772)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN (ScriptBytecodeAdapter.java:
118)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0 (ScriptBytecodeAdapter.java:
142)
at org.codehaus.groovy.tools.shell.InteractiveShellRunner.run (InteractiveShellRunner.groovy:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke (Method.java:597)
at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke (ReflectionMetaMethod.java:64)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke (MetaClassHelper.java:537)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:772)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:614)
at org.codehaus.groovy.runtime.Invoker.invokePogoMethod (Invoker.java:98)
at org.codehaus.groovy.runtime.Invoker.invokeMethod (Invoker.java:79)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod (InvokerHelper.java:74)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN (ScriptBytecodeAdapter.java:158)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod0 (ScriptBytecodeAdapter.java:201)
at org.codehaus.groovy.tools.shell.Groovysh.run (Groovysh.groovy:446)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke (Method.java:597)
at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke (ReflectionMetaMethod.java:64)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke (MetaClassHelper.java:537)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:772)
at groovy.lang.MetaClassImpl.invokeMethod (MetaClassImpl.java:614)
at org.codehaus.groovy.runtime.Invoker.invokePogoMethod (Invoker.java:98)
at org.codehaus.groovy.runtime.Invoker.invokeMethod (Invoker.java:79)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod (InvokerHelper.java:74)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN (ScriptBytecodeAdapter.java:158)
at org.codehaus.groovy.tools.shell.Groovysh.main (Groovysh.groovy:591)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke (Method.java:597)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader (GroovyStarter.java:101)
at org.codehaus.groovy.tools.GroovyStarter.main (GroovyStarter.java:130)
groovy0):000>


Daniel.Sun added a comment - 23/Sep/07 04:32 AM

If possible, please provide an entry to access the original full stacktrace to report bug


Guillaume Laforge added a comment - 23/Sep/07 04:36 AM

Agreed Daniel. With the -d flag (d for debug), we should be allowed to see the full stacktrace.


Jason Dillon added a comment - 28/Sep/07 01:09 AM

I'm not really sure what else that can be easily trimmed out of the stack traces... I've already trimmed things up to the groovysh_evaluate.run invocation. And ya, you should see the full traces when --debug is set.


Guillaume Laforge added a comment - 28/Sep/07 02:28 AM

Several packages should be filtered by default:

groovy.*/*
org.codehaus.groovy.*/*
java.*/*
javax.*/*
sun.*/*


Danno Ferrin added a comment - 28/Sep/07 11:23 AM

I lifted the sanitize stack trace stuff from grails and moved it into org.codehaus.groovy.runtime.StackTraceUtils, I am using it in GroovyConsole.

Just updated the defaults to reflect Guillaume's default.

The defaults can be changed by setting the system property "groovy.sanitized.stacktraces" to a comma/whitespace separated list of class prefixes (no globbing or regexing, not that advanced). This hast to be done before the class is loaded however.

I tried looking into getting this added to new shell, but ran out of time and the fix in console was working.


Jason Dillon added a comment - 28/Sep/07 03:15 PM

I'm not sure that it is a good idea to filter these packages... since sometimes exceptions come from classes in those packages, which ends up producing quite unusable stack traces.


Danno Ferrin added a comment - 28/Sep/07 03:37 PM - edited

In the Groovy console I address that issue via View->Show Full Stack Traces. Perhaps a prefs could be set to sanitize? "\= show-full-stack".

Also, when a stack trace is sanitized the throwable is logged first to the 'StackTrace' logger. You could add a log listener, clone the throwables and store them in ' _ ' as the "return value". This allows the user to '_ .printStackTrace()' to get the full stack if it is confusing. If you do a deep sanitize you may want to catch only the first one per iteration.


Jason Dillon added a comment - 30/Sep/07 09:46 AM

Ya, I think it should be fine add a preference to show the full stack.... I will look at StackTraceUtils and see how I can use it in groovysh.


Jason Dillon added a comment - 01/Oct/07 12:57 AM

StackTraceUtils looks good... except its spitting out logging crap, which makes the output even harder to grok... I think we need to remove that logging in StackTraceUtils... and then I'm happy happy to add this.


Jason Dillon added a comment - 01/Oct/07 03:00 AM

Um... I think I'm just gonna rip out that logging... if someone is using StackTraceUtils and they are worried about losing trace data, they should either log it themselves... or not use StackTraceUtils.

I'm gonna hook this up and use the sanitize-stack-trace preference (ala \=) to flip it on or off. And when --verbose is set, then it will override, so they always get the non-sanitize stack trace.

Will that work for everyone?


Jason Dillon added a comment - 01/Oct/07 03:03 AM

I've hooked up StackTraceUtils to sanitize the stack trace by default. Lemme know if there is more filtering/sanitization you want to see.


Jason Dillon made changes - 01/Oct/07 03:03 AM
Field Original Value New Value
Resolution Fixed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]
Guillaume Laforge added a comment - 01/Oct/07 03:19 AM

Cool, I'll try this out.