smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.25k stars 708 forks source link

Misleading error messages with {capture} #1032

Open SlowFox71 opened 3 months ago

SlowFox71 commented 3 months ago

If in a template with a {capture} block e.g. a TypError occurs within the content of the block, a misleading error message Not matching {capture}{/capture} in 'file:menuitem.tpl' is created with a backtrace like this:

#0 [...]/smarty-5.0.2/src/Runtime/CaptureRuntime.php(158): Smarty\Runtime\CaptureRuntime->error()
#1 [internal function]: Smarty\Runtime\CaptureRuntime->endRender()
#2 [...]/smarty-5.0.2/src/Template.php(185): call_user_func()
#3 [...]/smarty-5.0.2/src/Template.php(287): Smarty\Template->render()
#4 [...]/smarty_compile/ca/14/77/ca1477d761222a02268be0083d90c89f1842f445_0.file_menu.tpl.php(147): Smarty\Template->renderSubTemplate()
#5 [...]/smarty-5.0.2/src/Template/GeneratedPhpFile.php(111): content_665a28c0dbf522_48026962()
#6 [...]/smarty-5.0.2/src/Template/Compiled.php(110): Smarty\Template\GeneratedPhpFile->getRenderedTemplateCode()
#7 [...]/smarty-5.0.2/src/Template.php(180): Smarty\Template\Compiled->render()
#8 [...]/smarty-5.0.2/src/Template.php(287): Smarty\Template->render()
#9 [...]/smarty_compile/3d/a4/5b/3da45bae079bd02187704c890744779d6127e37f_0.file_page.tpl.php(102): Smarty\Template->renderSubTemplate()
#10 [...]/smarty-5.0.2/src/Template/GeneratedPhpFile.php(111): content_6657a72d813116_59350783()
#11 [...]/smarty-5.0.2/src/Template/Compiled.php(110): Smarty\Template\GeneratedPhpFile->getRenderedTemplateCode()
#12 [...]/smarty-5.0.2/src/Template.php(180): Smarty\Template\Compiled->render()
#13 [...]/smarty-5.0.2/src/Template.php(653): Smarty\Template->render()
#14 [...]/smarty-5.0.2/src/Template.php(586): Smarty\Template->_execute()
#15 [...]/smarty-5.0.2/src/Smarty.php(2122): Smarty\Template->fetch()

It takes some time to realize what really happens and strip the {capture} to get the actual error. I don't know if it is technically possible, but if yes, wouldn't it be far better to just pass the error (or at least the message) along so the real problem can be identified?