quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.49k stars 2.59k forks source link

Qute: Improve error column location in error message #26479

Open JessicaJHee opened 2 years ago

JessicaJHee commented 2 years ago

Description

After building the Quarkus application, this a sample of the error that is received.

 [error]: Build step io.quarkus.qute.deployment.QuteProcessor#processTemplateErrors threw an exception: io.quarkus.qute.TemplateException: Found incorrect expressions (2):
        [1] ItemResource/items.html:13:22 - {item.pric}: Property/method [pric] not found on class [org.acme.qute.Item] nor handled by an extension method
        [2] ItemResource/items.html:16:47 - {item.discountedPricesss}: Property/method [discountedPricesss] not found on class [org.acme.qute.Item] nor handled by an extension method

When trying to capture this error to display in an IDE, we would need the column value to be at the error token in order to highlight the error range correctly. Currently, the error column location is reported at the cursor in the screenshot, causing the underline to be in the incorrect position.

image {#if item|.pric < 15} image <strong>|{item.discountedPricesss}

Implementation ideas

To fix this, it would be nice to have the location changed to: {#if item.|pric < 15} <strong>{item.|discountedPricesss}

quarkus-bot[bot] commented 2 years ago

/cc @mkouba

mkouba commented 2 years ago

I'm not sure I fully understand the isssue but the format has been changed in 2.10 (https://github.com/quarkusio/quarkus/pull/25810) and the error message should look like: [1] ItemResource/items.html:13:22 - {item.pric}: Property/method [pric] not found on class [org.acme.qute.Item] nor handled by an extension method, i.e. the column points to the start of the pric property. Is that something what you're looking for, or?

JessicaJHee commented 2 years ago

I'm apologize, the sample I pasted was incorrect. The format of the error message is perfect, just the location of the column. Currently, the error is reported at 13:22, which is at the end of the item property and not at the start of the pricproperty. I believe it should be reported at 13:23. In the second error, the error is reported at 16:47, where it would be preferred to be reported at 16:53 (start of the discountedPricesss element)

Current behavior (where '|' indicates the reported location of the error) :

{#if item|.pric < 15}    [13:22]
<strong>|{item.discountedPricesss}    [16:47]

Preferred behavior:

{#if item.|pric < 15}    [13:23]
<strong>{item.|discountedPricesss}    [16:53]
mkouba commented 2 years ago

I see. So in general Qute reports the beginning of an expression, i.e. column 47 for {item.discountedPricesss}. This is expected. However, in case of a section parameter ({#if}), it's a bit more complicated because there is no expression node in the template tree. I think that we try to compute the value and it seems there's a bug. It should be column 18 or something like that (the beginning of the expression).

Now, we could try to improve the "precision" and match an actual property instead of an expression but we need to find out how difficult it would be (and whether it's worth the effort) and also fix the bug first.

mkouba commented 2 years ago

I don't see an easy way to reliably identify the column of an expression used as a section param. Therefore, we'll report the column of the section for the moment and we'll try to improve the io.quarkus.qute.SectionHelperFactory API later.