mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 20:06:31 +00:00
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:
@@ -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
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user