sysgears / grain

Grain is a lightweight and powerful static website generator with custom themes to help create static, SEO-friendly websites or a blog in no time.
https://sysgears.com/grain
Other
160 stars 30 forks source link

Display a nice error for commands instead of a stack trace #3

Closed bouquetf closed 10 years ago

bouquetf commented 10 years ago

Here's an example : When typing :

$ grainw create-post

Grain displays this stack trace :

java.lang.IllegalArgumentException: wrong number of arguments at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at org.codehaus.groovy.runtime.metaclass.TransformMetaMethod.invoke(TransformMetaMethod.java:55) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass$1.invoke(ClosureMetaClass.java:259) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at com.sysgears.grain.Application.run(Application.groovy:120) at com.sysgears.grain.Application$run.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112) at com.sysgears.grain.Main.main(Main.groovy:76) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.sysgears.grain.SiteLauncher.run(SiteLauncher.java:110) at com.sysgears.grain.SiteLauncher.main(SiteLauncher.java:39)

I think it would be better to handle this error and display an help for the command. For example :

create-post needs 1 argument grainw create-post

bouquetf commented 10 years ago

Got it with 0.3.3 release

larixer commented 10 years ago

Hello Frederic,

Yup. Agree. Stack trace is not a nice reaction at all. I think we can somehow find out from Groovy the number of required and optional arguments for closure for now. In the future we are going to move commands into their own scripts, pretty much like it's done in Grails.

Victor