On Sep 28, 2012, at 11:37 AM, Thomas Mortagne <[email protected]> wrote:
> Hi devs, > > I find myself starting to copy past a lot of stuff from one > ScriptService to another and I wanted to discuss with you think I find > common enough to be put in a AbstractScriptService in > xwiki-commons-script to be reused everywhere. > > As a discussion based I committed a first thing in > https://github.com/xwiki/xwiki-commons/commit/a19c6df56fa984dacc9a8eeb50bb9dc4b9035376 > in a branch. > > So here are some ideas: > * helper to set/get exception that every method is supposed to catch > to make error handling in languages like velocity easier (in the > commit) > * helper to find a proper "safe" wrapper based on the type of an > object (there is a example of such helper in > https://github.com/xwiki/xwiki-commons/tree/master/xwiki-commons-core/xwiki-commons-extension/xwiki-commons-extension-api/src/main/java/org/xwiki/extension/internal/safe) > > Any other ? > > WDYT ? I'm still hesitating. I've discussed this in the past and my idea has always been to try to hide this as a generic feature of Velocity rather than making it visible. Let me explain. My ideal solution is this: * Add a velicity uberspector so that any method that is called that throws an exception returns a null instead and saves the exception automatically in the context and then provide some Velocity tool to easily access the exception My rationale is the following: * We have this need for Velocity but not for other scripting languages such as Groovy, Ruby, Python. Basically we have this issue only for templating languages that don't support exception handling. * It's a pity that when coding in groovy I can't use Groovy's exception handling mechanism and have to do something hackish instead. Thus to conclude, my preference is: * Don't change ScriptService * Add an uberspector to handle exceptions in Velocity * Progressively modify our existing script apis to not do this hacky try/catch and null setting and for new script apis do the normal thing Now, if we really want to have all our script languages return null instead of throw an exception, then I'd suggest that this is not the job of the implementer of Script Service to do this but instead use a Dynamic Proxy to wrap ScriptService and delegate to the script service implementation and in the dynamic proxy do the try/catch and null setting. Thanks -Vincent _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs

