phug-php / phug

Phug - The Pug Template Engine for PHP
https://phug.selfbuild.fr
MIT License
63 stars 3 forks source link

Template error location always points to line 1, offset 1 when using FileAdapter #17

Closed char101 closed 6 years ago

char101 commented 6 years ago

Hello,

When the cache file does not exist before, the error message in pug error page always points to line 1, offset 1. After I refresh the browser, the error location now points to the correct line and offset.

char101 commented 6 years ago

Update: the line is correct, but the offset is not. At least when the error is Call to undefined function, the offset given is 1 while the function name starts in the 10th column.

kylekatarnls commented 6 years ago

Hi, the offset is the begining of the expression (pug token). As PHP error does not contains the offset, we cannot be more accurate. I confirm the first problem, we not yet save the sourcemap in cache so stack trace only work with fresh rendering (or cache disabled).

kylekatarnls commented 6 years ago

Hi, changes made for Laravel compatibility earlier should have fix this bug. Source is recompiled when an error occurs on a cached file. The line and offset are given for the matching Pug token (PHP error does not have offset, so we have to approximate) it will not be the exact PHP code offset, it will be in the expression(s) after the offset in the same token. If the offsetLength given > 1, it means the errors should be bewteen offset and offset + offsetLength.

Can you confirm, you now get accurate error locations according to this?

char101 commented 6 years ago

Thanks for the enhancement. The project I was working on is currently on hold since I am working on another non-PHP project so I cannot test it right now.