phug-php / phug

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

Error if mixin is never called #27

Closed rodion-k closed 6 years ago

rodion-k commented 6 years ago

Hello,

I encountered an issue with the following code: /tmp/test/jade/_test.jade

mixin svgDown
  p test

mixin svgCheckboxChecked
  p I will never be called

+svgDown

Then cache directory: phug cache-directory /tmp/test/jade /tmp/test/jade-dist And render:

Phug::renderFile("/tmp/test/jade/_test.jade", [], ['cache_dir' => '/tmp/test/jade-dist']);

I expected to get:

<p>test</p>

But I actually get:

Exception 'Phug\RendererException' with message 'ErrorException in /tmp/test/jade/_test.jade:
Undefined index: svgCheckboxChecked on line 0, offset 0

    1 | mixin svgDown
    2 |   p test
    3 | 
    4 | mixin svgCheckboxChecked
    5 |   p I will never be called
    6 | 
    7 | +svgDown
'

in /vendor/phug/renderer/src/Phug/Renderer/Partial/Debug/DebuggerTrait.php:167

Stack trace:
#0 /vendor/phug/renderer/src/Phug/Renderer/Partial/Debug/DebuggerTrait.php(230): Phug\Renderer->getRendererException(Object(ErrorException), 1, 0, 0, 'mixin svgDown\n ...', '/tmp/test/jade/...', Array, Array)
#1/vendor/phug/renderer/src/Phug/Renderer/Partial/Debug/DebuggerTrait.php(347): Phug\Renderer->getDebuggedException(Object(ErrorException), 1, 'mixin svgDown\n ...', '/tmp/test/jade/...', Array, Array)
#2 /vendor/phug/renderer/src/Phug/Renderer/Partial/AdapterTrait.php(164): Phug\Renderer->handleError(Object(ErrorException), 1, '/tmp/test/jade/...', '<?php $pugModul...', Array, Array)
#3 /vendor/phug/renderer/src/Phug/Renderer/Partial/AdapterTrait.php(219): Phug\Renderer->handleHtmlEvent(Object(Phug\Renderer\Event\HtmlEvent), Array, '/tmp/test/jade/...', Object(Closure))
#4 /vendor/phug/renderer/src/Phug/Renderer.php(144): Phug\Renderer->callAdapter('render', '/tmp/test/jade/...', NULL, Object(Closure), Array)
#5 /vendor/phug/phug/src/Phug/Phug.php(169): Phug\Renderer->renderFile('/tmp/test/jade/...', Array)

If you delete svgCheckboxChecked then everything is fine

Thanks!

kylekatarnls commented 6 years ago

Hello,

I'm sorry, I was not able to reproduce. I used the cache CLI, then render the cached file with a mixin called and a mixin not called and It just rendered <p>test</p>

Could you try:

Thanks.

kylekatarnls commented 6 years ago

Hi, I just ran into your bug fortuitously. A template that worked just before. I must identify the random factor for this.

kylekatarnls commented 6 years ago

Hi, after running composer update and clearing your cache directory, it should not happen again.

rodion-k commented 6 years ago

It works, thanks @kylekatarnls!