Search in sources :

Example 6 with SoyTofuException

use of com.google.template.soy.tofu.SoyTofuException in project closure-templates by google.

the class TofuExceptionsTest method testExceptions_wrongTypeFuture.

@Test
public void testExceptions_wrongTypeFuture() {
    SoyDict data = SoyValueConverterUtility.newDict("foo", Futures.immediateFuture("not a record"));
    // This error occurs due to data of the wrong type, hidden behind a future.
    try {
        tofu.newRenderer("ns.callerTemplate").setData(data).render();
        fail();
    } catch (SoyTofuException ste) {
        assertThat(ste).hasCauseThat().isNull();
        assertThat(ste).hasMessageThat().isEqualTo("When evaluating \"$foo.boo\": Parameter type mismatch: attempt to bind value " + "'not a record' (a StringData) to parameter 'foo' which has a declared type " + "of '[bad: string, boo: int]'.");
        assertThat(ste.getStackTrace()[0].toString()).isEqualTo("ns.calleeTemplate(no-path:8)");
        assertThat(ste.getStackTrace()[1].toString()).isEqualTo("ns.calleeTemplate(no-path:10)");
        assertThat(ste.getStackTrace()[2].toString()).isEqualTo("ns.callerTemplate(no-path:5)");
    }
}
Also used : SoyTofuException(com.google.template.soy.tofu.SoyTofuException) SoyDict(com.google.template.soy.data.SoyDict) Test(org.junit.Test)

Example 7 with SoyTofuException

use of com.google.template.soy.tofu.SoyTofuException in project closure-templates by google.

the class TofuExceptionsTest method testExceptions_failedFuture.

@Test
public void testExceptions_failedFuture() {
    Exception futureFailureCause = new Exception("boom");
    SoyDict data = SoyValueConverterUtility.newDict("foo", immediateFailedFuture(futureFailureCause));
    // This error occurs due to a failed future.
    try {
        tofu.newRenderer("ns.callerTemplate").setData(data).render();
        fail();
    } catch (SoyTofuException ste) {
        assertThat(ste).hasMessageThat().isEqualTo("When evaluating \"$foo.boo\": Error dereferencing future");
        SoyFutureException sfe = (SoyFutureException) ste.getCause();
        assertThat(sfe).hasMessageThat().isEqualTo("Error dereferencing future");
        assertThat(sfe).hasCauseThat().isEqualTo(futureFailureCause);
        assertThat(ste.getStackTrace()[0].toString()).isEqualTo("ns.calleeTemplate(no-path:10)");
        assertThat(ste.getStackTrace()[1].toString()).isEqualTo("ns.callerTemplate(no-path:5)");
    }
}
Also used : SoyTofuException(com.google.template.soy.tofu.SoyTofuException) SoyDict(com.google.template.soy.data.SoyDict) SoyFutureException(com.google.template.soy.data.SoyFutureException) SoyTofuException(com.google.template.soy.tofu.SoyTofuException) SoyFutureException(com.google.template.soy.data.SoyFutureException) Test(org.junit.Test)

Aggregations

SoyTofuException (com.google.template.soy.tofu.SoyTofuException)7 SoyDict (com.google.template.soy.data.SoyDict)6 Test (org.junit.Test)6 SoyFutureException (com.google.template.soy.data.SoyFutureException)2 EvalVisitorFactoryImpl (com.google.template.soy.sharedpasses.render.EvalVisitorFactoryImpl)1 RenderException (com.google.template.soy.sharedpasses.render.RenderException)1 RenderVisitor (com.google.template.soy.sharedpasses.render.RenderVisitor)1 TemplateNode (com.google.template.soy.soytree.TemplateNode)1