Search in sources :

Example 6 with JapidCompilationException

use of cn.bran.japid.compiler.JapidCompilationException in project japid42 by branaway.

the class JapidRenderer method handleException.

public static RenderResult handleException(Throwable e) throws RuntimeException {
    if (!presentErrorInHtml)
        if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        else
            throw new RuntimeException(e);
    // if (Play.mode == Mode.PROD)
    // throw new RuntimeException(e);
    //
    Class<? extends JapidTemplateBaseWithoutPlay> rendererClass = getErrorRendererClass();
    if (e instanceof JapidTemplateException) {
        RenderResult rr = RenderInvokerUtils.invokeRender(rendererClass, (JapidTemplateException) e);
        return (rr);
    }
    if (e instanceof RuntimeException && e.getCause() != null)
        e = e.getCause();
    if (e instanceof JapidCompilationException) {
        JapidCompilationException jce = (JapidCompilationException) e;
        JapidTemplateException te = JapidTemplateException.from(jce);
        RenderResult rr = RenderInvokerUtils.invokeRender(rendererClass, te);
        return (rr);
    }
    e.printStackTrace();
    // find the latest japidviews exception or the controller that caused
    // the exception
    StackTraceElement[] stackTrace = e.getStackTrace();
    for (StackTraceElement ele : stackTrace) {
        String className = ele.getClassName();
        if (className.startsWith("japidviews")) {
            int lineNumber = ele.getLineNumber();
            RendererClass applicationClass = japidClasses.get(className);
            if (applicationClass != null) {
                // let's get the line of problem
                int oriLineNumber = applicationClass.mapJavaLineToJapidScriptLine(lineNumber);
                if (oriLineNumber > 0) {
                    if (rendererClass != null) {
                        String path = applicationClass.getScriptPath();
                        JapidTemplateException te = new JapidTemplateException("Japid Error", path + "(" + oriLineNumber + "): " + e.getClass().getName() + ": " + e.getMessage(), oriLineNumber, path, applicationClass.getJapidSourceCode());
                        RenderResult rr = RenderInvokerUtils.invokeRender(rendererClass, te);
                        return (rr);
                    }
                }
            }
        } else if (className.startsWith("controllers.")) {
            if (e instanceof RuntimeException)
                throw (RuntimeException) e;
            else
                throw new RuntimeException(e);
        }
    }
    JapidTemplateException te = new JapidTemplateException(e);
    RenderResult rr = RenderInvokerUtils.invokeRender(rendererClass, te);
    return rr;
// if (e instanceof RuntimeException)
// throw (RuntimeException) e;
// else
// throw new RuntimeException(e);
}
Also used : JapidCompilationException(cn.bran.japid.compiler.JapidCompilationException) JapidTemplateException(cn.bran.japid.exceptions.JapidTemplateException) RendererClass(cn.bran.japid.rendererloader.RendererClass)

Aggregations

JapidCompilationException (cn.bran.japid.compiler.JapidCompilationException)6 JapidTemplateException (cn.bran.japid.exceptions.JapidTemplateException)3 RendererClass (cn.bran.japid.rendererloader.RendererClass)3 File (java.io.File)3 VirtualFile (play.vfs.VirtualFile)3 IOException (java.io.IOException)2 CompilationException (play.exceptions.CompilationException)2 TranslateTemplateTask (cn.bran.japid.compiler.TranslateTemplateTask)1 JapidTemplate (cn.bran.japid.template.JapidTemplate)1 RenderResult (cn.bran.japid.template.RenderResult)1 HashSet (java.util.HashSet)1 CategorizedProblem (org.eclipse.jdt.core.compiler.CategorizedProblem)1 IProblem (org.eclipse.jdt.core.compiler.IProblem)1 ClassFile (org.eclipse.jdt.internal.compiler.ClassFile)1 Validation (play.data.validation.Validation)1