smarty-php / smarty-php/smarty

Misleading error messages with {capture}

Open
#1,032 2 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
2.3k
Forks
709
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/Runtime/CaptureRuntime.php around line 158 and trace how the capture block's endRender error is reached through src/Template.php. Reproduce a TypeError inside a {capture} block and verify that the original error or message and its useful backtrace are preserved instead of reporting only a misleading unmatched-capture error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.