fixed error filename/line when an error occurs in an included file

To be able to cover all cases, we need to catch the exception when we
know the execution context (the block being rendered). The only
possibility is to actually try/catch exceptions in the displayBlock()
method directly.
This commit is contained in:
Fabien Potencier
2013-10-27 14:47:59 +01:00
parent de985a872f
commit 1cdc913f4c
2 changed files with 18 additions and 6 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
* 1.14.2 (2013-XX-XX)
* n/a
* fixed error filename/line when an error occurs in an included file
* 1.14.1 (2013-10-15)
+17 -5
View File
@@ -127,12 +127,24 @@ abstract class Twig_Template implements Twig_TemplateInterface
{
$name = (string) $name;
$template = null;
if (isset($blocks[$name])) {
$b = $blocks;
unset($b[$name]);
call_user_func($blocks[$name], $context, $b);
$template = $blocks[$name][0];
$block = $blocks[$name][1];
unset($blocks[$name]);
} elseif (isset($this->blocks[$name])) {
call_user_func($this->blocks[$name], $context, $blocks);
$template = $this->blocks[$name][0];
$block = $this->blocks[$name][1];
}
if (null !== $template) {
try {
$template->$block($context, $blocks);
} catch (Twig_Error $e) {
throw $e;
} catch (Exception $e) {
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getTemplateName(), $e);
}
} elseif (false !== $parent = $this->getParent($context)) {
$parent->displayBlock($name, $context, array_merge($this->blocks, $blocks));
}
@@ -276,7 +288,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
throw $e;
} catch (Exception $e) {
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, null, $e);
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getTemplateName(), $e);
}
}