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 - introduce strict rendering #18227

Merged
merged 1 commit into from
Jul 3, 2021

Conversation

mkouba
Copy link
Contributor

@mkouba mkouba commented Jun 29, 2021

  • i.e. if any expression is evaluated to "not found" value a
    TemplateException is thrown and rendering is aborted
  • it's enabled by default
  • it can be disabled via io.quarkus.qute.strict-rendering=false

@quarkus-bot quarkus-bot bot added the area/qute The template engine label Jun 29, 2021
@mkouba
Copy link
Contributor Author

mkouba commented Jun 29, 2021

Note that this is a breaking change - the default behavior has changed. Type-safe templates are not affected though.

This PR is related to #18177.

@quarkus-bot quarkus-bot bot added area/codestarts area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/platform Issues related to definition and interaction with Quarkus Platform labels Jun 29, 2021
@@ -50,6 +50,8 @@ public static String readQuteFile(CodestartResource projectResource, Source sour
final Engine engine = Engine.builder().addDefaults()
.addResultMapper(new MissingValueMapper())
.removeStandaloneLines(true)
// TODO This needs to be revisited
.strictRendering(false)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @ia3andy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so what cases is it that you see that will break here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not examine the failures but a lot of codestarts and devtools tests failed so it's definitely related. A quick scan example: "Property "parent" not found on base object "java.util.HashMap" in expression {parent} in template 1 on line 6" in theQuarkusExtensionCodestartGenerationTest.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting - now curious which of these are actual bugs.

should map lookups be considered valid or is expectation you do {obj.parent ? false} ?

sucks we didnt notice this before 2.0 :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need to take a look at the tests. But it can be a bug in the test too ;-).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I checked the tests and the problematic pattern looks like {#if uberjar}<quarkus.package.type>uber-jar</quarkus.package.type>{/if}. Previously this didn't fail because "not found" was considered a falsy value. In this PR, we assume that "not found" cannot be evaluated correctly by default and thus the rendering fails. Note that null would be OK because it means that we found something...

With strict rendering enabled the template would have to use something like {#if uberjar.or(false)} (elvis operator would not work here because it's a param of a section) or even {#if containsKey('uberjar')} (because the data object is a manually created Map).

That said, I think it's ok to disable the strict rendering for situations like these. I'll let @ia3andy to decide later. For now, I will add a more explaining comment.

should map lookups be considered valid or is expectation you do {obj.parent ? false} ?

I don't think we should add a special handling for any type. That might be even more confusing.

@FroMage
Copy link
Member

FroMage commented Jun 30, 2021

I'm not sure. What's the rationale for changing the default in the case of non-type-safe templates? Seems to me that they're not type-safe so why throw? 🤷

@mkouba
Copy link
Contributor Author

mkouba commented Jun 30, 2021

I'm not sure. What's the rationale for changing the default in the case of non-type-safe templates? Seems to me that they're not type-safe so why throw? shrug

So the main motivation is to help users to spot the problems with typos and similar kind of errors. Of course, this change does not affect users of @CheckedTemplate but it could help those who can't/don't want to use them. Note that qute is also used "standalone" and in this mode no type-safe checks are supported.

For example, a template without type-safe checks: My hero names: {hero.nams} and there's public class Hero { public String names; }. Currently, this expression results in My hero names: NOT_FOUND by default. After this change, the rendering would fail with a message like Property "nams" not found in expression {hero.nams} in template hero.html on line 2 by default.

Note that before this PR it was possible to change the quarkus.qute.property-not-found-strategy to throw an exception in similar cases. However, this only worked for standalone expressions, not for expressions used in sections, e.g. #{if hero.isFamou}.

Copy link
Contributor

@gastaldi gastaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@maxandersen
Copy link
Contributor

To be clear my main ask is that qute stand-alone at least don't let obvious errors be ignored. Ie. Typos In if statements.

Should at least be possible to enable.

@mkouba mkouba added this to the 2.1 - main milestone Jul 1, 2021
@mkouba mkouba force-pushed the qute-strict-rendering branch 2 times, most recently from b679712 to cabafef Compare July 2, 2021 08:12
@quarkusio quarkusio deleted a comment from quarkus-bot bot Jul 2, 2021
@quarkusio quarkusio deleted a comment from quarkus-bot bot Jul 2, 2021
@quarkusio quarkusio deleted a comment from quarkus-bot bot Jul 2, 2021
@quarkusio quarkusio deleted a comment from quarkus-bot bot Jul 2, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Jul 2, 2021

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building cabafef

Status Name Step Test failures Logs Raw logs
JVM Tests - JDK 11 Build Test failures Logs Raw logs
JVM Tests - JDK 11 Windows Build ⚠️ Check → Logs Raw logs
JVM Tests - JDK 16 Build ⚠️ Check → Logs Raw logs

Full information is available in the Build summary check run.

Test Failures

⚙️ JVM Tests - JDK 11 #

📦 extensions/vertx-http/deployment

io.quarkus.vertx.http.testrunner.tags.ExcludeTagsTestCase.checkTestsAreRun line 73 - More details - Source on GitHub

@quarkusio quarkusio deleted a comment from quarkus-bot bot Jul 2, 2021
@mkouba
Copy link
Contributor Author

mkouba commented Jul 2, 2021

Hm, I can see the following failure in JVM Tests - JDK 16:

Caused by: org.apache.maven.plugin.MojoExecutionException: Deployment artifact io.quarkus:quarkus-resteasy-reactive-kotlin-deployment::jar:999-SNAPSHOT is missing the following dependencies from its configuration: io.quarkus:quarkus-smallrye-context-propagation-deployment::jar, io.quarkus:quarkus-vertx-core-deployment::jar, io.quarkus:quarkus-netty-deployment::jar, io.quarkus:quarkus-jsonp-deployment::jar

Does it ring a bell? @gsmet @geoand

@geoand
Copy link
Contributor

geoand commented Jul 2, 2021

Huh.... I don't see that in #18222 for example that was rebased onto the new Kotlin layout

@quarkus-bot
Copy link

quarkus-bot bot commented Jul 2, 2021

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building ecb7b62

Status Name Step Test failures Logs Raw logs
JVM Tests - JDK 11 Build ⚠️ Check → Logs Raw logs
JVM Tests - JDK 11 Windows Build ⚠️ Check → Logs Raw logs
JVM Tests - JDK 16 Build ⚠️ Check → Logs Raw logs

@aloubyansky
Copy link
Member

#18353 should fix the CI

@quarkusio quarkusio deleted a comment from quarkus-bot bot Jul 2, 2021
- i.e. if any expression is evaluated to "not found" value a
TemplateException is thrown and rendering is aborted
- it's enabled by default
- it can be disabled via io.quarkus.qute.strict-rendering=false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/codestarts area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/platform Issues related to definition and interaction with Quarkus Platform area/qute The template engine release/breaking-change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants