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
On invalid LESS, throw exception rather than emit blanks #478
Conversation
This patch makes lessphp throw errors when it is called to compile LESS code that references undefined variables or mixins. A mixin invocation will cause an exception to be thrown if it fails to match, whether it is because no mixin of that name exists, or because the invocation fails to match against the signatures or guards of defined mixins. This is consistent with the behavior of the reference LESS implementation. The patch removes cases from tests/inputs/* that fail to compile. A new test suite, ErrorHandlingTest.php, verifies the new error-throwing behavior.
Fixes #475. |
On invalid LESS, throw exception rather than emit blanks
Awesome, thanks for the patch |
After this patch trying to compile twitter bootstrap results in a |
Hrm, I'll investigate. |
@mitom I'm pretty sure this is an issue with Bootstrap... Looking at the bootstrap LESS implementation I found a minimum test case:
If you render this before the patch you get
After the patch you get the error you are reporting. Can anyone confirm? |
This seems to be consistent with the nodejs implementation of less NameError: .pull-right > .dropdown-menu is undefined in less/common/common.less:11:6 |
I'm running lessc 1.3.3 (LESS Compiler) [JavaScript] so it seems this is new syntax introduced since then that bootstrap is using that lessphp doesn't yet support. As an interim measure until we reflect that new syntax we might want to consider a variable --hide-errors or something similar? Although it seems surfacing the error is a much better thing exactly for this reason. |
@atdt said:
This is not consistent with reference LESS implementation, specifically as it relates to guards. If a guard must match in order to avoid throwing an exception there is no point to having the guard. Guards as they exist in lessphp now are either matching (in which case the selectors, properties, etc. will be added) or they throw an exception in which case the whole .less file not be rendered. The last two tests in It is not possible to run the doc examples anymore. IMO, it is better to allow guards by reverting the undefined mixin error to a break. cc/ @leafo |
This patch makes lessphp throw errors when it is called to compile LESS code
that references undefined variables or mixins. A mixin invocation will cause an
exception to be thrown if it fails to match, whether it is because no mixin of
that name exists, or because the invocation fails to match against the
signatures or guards of defined mixins. This is consistent with the behavior of
the reference LESS implementation.
The patch removes cases from tests/inputs/* that fail to compile. A new test
suite, ErrorHandlingTest.php, verifies the new error-throwing behavior.