Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qute: namespace issue in included templates #20701

Closed
FroMage opened this issue Oct 12, 2021 · 3 comments · Fixed by #20739
Closed

Qute: namespace issue in included templates #20701

FroMage opened this issue Oct 12, 2021 · 3 comments · Fixed by #20739
Labels
area/qute The template engine kind/bug Something isn't working
Milestone

Comments

@FroMage
Copy link
Member

FroMage commented Oct 12, 2021

Describe the bug

Given the following templates:

Application/index.html:

{#include main.html }
{#title}Artists{/title}

{#if globals:user}
{/if}

{/include}

main.html:

<!DOCTYPE html>
<html>
    <head>
        <title>{#insert title /}</title>
        <meta charset="UTF-8">
    </head>
    <body>
        <div class="pre-footer">
            {#if global:user.alerts}
 {/if}
         </div>
    </body>
</html>

I'm getting the following exception at run-time when rendering it:

2021-10-12 15:30:39,495 ERROR [org.jbo.res.rea.com.cor.AbstractResteasyReactiveContext] (executor-thread-0) Request failed: io.quarkus.qute.TemplateException
	at io.quarkus.qute.CompletedStage.get(CompletedStage.java:44)
	at io.quarkus.qute.MultiResultNode.process(MultiResultNode.java:20)
	at io.quarkus.qute.MultiResultNode.process(MultiResultNode.java:20)
	at io.quarkus.qute.TemplateImpl$TemplateInstanceImpl.lambda$renderData$3(TemplateImpl.java:110)
	at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
	at java.base/java.util.concurrent.CompletableFuture.uniWhenCompleteStage(CompletableFuture.java:883)
	at java.base/java.util.concurrent.CompletableFuture.whenComplete(CompletableFuture.java:2315)
	at java.base/java.util.concurrent.CompletableFuture.whenComplete(CompletableFuture.java:143)
	at io.quarkus.qute.TemplateImpl$TemplateInstanceImpl.renderData(TemplateImpl.java:104)
	at io.quarkus.qute.TemplateImpl$TemplateInstanceImpl.renderAsync(TemplateImpl.java:90)
	at io.smallrye.context.impl.wrappers.SlowContextualSupplier.get(SlowContextualSupplier.java:21)
	at io.smallrye.mutiny.operators.uni.builders.UniCreateFromCompletionStage.subscribe(UniCreateFromCompletionStage.java:24)
	at io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)
	at io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni.subscribe(UniOnItemTransformToUni.java:25)
	at io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)
	at io.smallrye.mutiny.groups.UniSubscribe.withSubscriber(UniSubscribe.java:50)
	at io.smallrye.mutiny.groups.UniSubscribe.with(UniSubscribe.java:90)
	at io.quarkus.resteasy.reactive.server.runtime.filters.FilterUtil.handleUniVoid(FilterUtil.java:60)
	at io.quarkus.resteasy.reactive.qute.runtime.TemplateResponseFilter$GeneratedServerResponseFilter$filter.filter(TemplateResponseFilter$GeneratedServerResponseFilter$filter.zig:58)
	at io.quarkus.resteasy.reactive.qute.runtime.TemplateResponseFilter$GeneratedServerResponseFilter$filter_Subclass.filter$$superforward1(TemplateResponseFilter$GeneratedServerResponseFilter$filter_Subclass.zig:151)
	at io.quarkus.resteasy.reactive.qute.runtime.TemplateResponseFilter$GeneratedServerResponseFilter$filter_Subclass$$function$$50.apply(TemplateResponseFilter$GeneratedServerResponseFilter$filter_Subclass$$function$$50.zig:41)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
	at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)
	at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
	at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
	at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
	at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
	at io.quarkus.resteasy.reactive.qute.runtime.TemplateResponseFilter$GeneratedServerResponseFilter$filter_Subclass.filter(TemplateResponseFilter$GeneratedServerResponseFilter$filter_Subclass.zig:318)
	at org.jboss.resteasy.reactive.server.spi.ResteasyReactiveContainerResponseFilter.filter(ResteasyReactiveContainerResponseFilter.java:10)
	at io.quarkus.resteasy.reactive.qute.runtime.TemplateResponseFilter$GeneratedServerResponseFilter$filter_Subclass.filter$$superforward1(TemplateResponseFilter$GeneratedServerResponseFilter$filter_Subclass.zig:134)
	at io.quarkus.resteasy.reactive.qute.runtime.TemplateResponseFilter$GeneratedServerResponseFilter$filter_Subclass$$function$$49.apply(TemplateResponseFilter$GeneratedServerResponseFilter$filter_Subclass$$function$$49.zig:41)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
	at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)
	at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
	at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
	at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
	at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
	at io.quarkus.resteasy.reactive.qute.runtime.TemplateResponseFilter$GeneratedServerResponseFilter$filter_Subclass.filter(TemplateResponseFilter$GeneratedServerResponseFilter$filter_Subclass.zig:221)
	at org.jboss.resteasy.reactive.server.handlers.ResourceResponseFilterHandler.handle(ResourceResponseFilterHandler.java:24)
	at org.jboss.resteasy.reactive.server.handlers.ResourceResponseFilterHandler.handle(ResourceResponseFilterHandler.java:9)
	at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)
	at io.quarkus.vertx.core.runtime.VertxCoreRecorder$13.runWith(VertxCoreRecorder.java:543)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
	at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
	at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: io.quarkus.qute.TemplateException: No namespace resolver found for: globals
	at io.quarkus.qute.EvaluatorImpl.evaluate(EvaluatorImpl.java:59)
	at io.quarkus.qute.ResolutionContextImpl$ChildResolutionContext.evaluate(ResolutionContextImpl.java:86)
	at io.quarkus.qute.IfSectionHelper$OperandCondition.evaluate(IfSectionHelper.java:182)
	at io.quarkus.qute.IfSectionHelper.resolve(IfSectionHelper.java:45)
	at io.quarkus.qute.SectionNode.resolve(SectionNode.java:34)
	at io.quarkus.qute.SectionNode$SectionResolutionContextImpl.execute(SectionNode.java:153)
	at io.quarkus.qute.SectionHelper$SectionResolutionContext.execute(SectionHelper.java:37)
	at io.quarkus.qute.Parser$1.resolve(Parser.java:1014)
	at io.quarkus.qute.SectionNode.resolve(SectionNode.java:34)
	at io.quarkus.qute.IncludeSectionHelper.resolve(IncludeSectionHelper.java:34)
	at io.quarkus.qute.SectionNode.resolve(SectionNode.java:34)
	at io.quarkus.qute.SectionNode$SectionResolutionContextImpl.execute(SectionNode.java:153)
	at io.quarkus.qute.SectionHelper$SectionResolutionContext.execute(SectionHelper.java:37)
	at io.quarkus.qute.Parser$1.resolve(Parser.java:1014)
	at io.quarkus.qute.SectionNode.resolve(SectionNode.java:34)
	... 42 more

Which is weird because both templates are type-checked:

@CheckedTemplate
public class Templates {
    public static native TemplateInstance main();
}

@Path("Application")
public class Application {

    @CheckedTemplate
    static class Templates {
        public static native TemplateInstance index();
    }
    
    @GET
    @Path("index")
    public TemplateInstance index() {
        return Templates.index();
    }
}

And I don't get errors at build-time about those.

Also, I'm not getting any line number for the error.

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@FroMage FroMage added the kind/bug Something isn't working label Oct 12, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Oct 12, 2021

/cc @mkouba

@quarkus-bot quarkus-bot bot added the area/qute The template engine label Oct 12, 2021
@FroMage
Copy link
Member Author

FroMage commented Oct 12, 2021

OK, found it, this is due to my globals missing the static modifiers on methods:

@TemplateExtension(namespace = "global")
public class Globals {
    public User user() {
        return null;
    }
    public int VARCHAR_SIZE() {
        return Util.VARCHAR_SIZE;
    }
}

What's weird is that this lets me pass build-time type-checking. In any case, the error message could be improved :)

@mkouba
Copy link
Contributor

mkouba commented Oct 12, 2021

What's weird is that this lets me pass build-time type-checking. In any case, the error message could be improved :)

Well, not all expressions/references that start with a namespace are validated during build. So far we only validate those with inject: and namespaces contributed by classes annotated with @TemplateData. Validation of namespaces coming from the template extension methods is on my TODO list.

In any case, the error message could be improved :)

+10

mkouba added a commit to mkouba/quarkus that referenced this issue Oct 13, 2021
- also improve the error message if no resolver is found for a namespace
at runtime
- resolves quarkusio#20701
@quarkus-bot quarkus-bot bot added this to the 2.5 - main milestone Oct 13, 2021
@aloubyansky aloubyansky modified the milestones: 2.5 - main, 2.4.0.Final Oct 18, 2021
aloubyansky pushed a commit to aloubyansky/quarkus that referenced this issue Oct 18, 2021
- also improve the error message if no resolver is found for a namespace
at runtime
- resolves quarkusio#20701

(cherry picked from commit 2cef352)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/qute The template engine kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants