diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 0878d1640..3ef765821 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -155,6 +155,17 @@ abstract class Twig_Template implements Twig_TemplateInterface try { $template->$block($context, $blocks); } catch (Twig_Error $e) { + if (!$e->getTemplateFile()) { + $e->setTemplateFile($template->getTemplateName()); + } + + // this is mostly useful for Twig_Error_Loader exceptions + // see Twig_Error_Loader + if (false === $e->getTemplateLine()) { + $e->setTemplateLine(-1); + $e->guess(); + } + 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); diff --git a/test/Twig/Tests/Fixtures/exceptions/undefined_template_in_child_template.test b/test/Twig/Tests/Fixtures/exceptions/undefined_template_in_child_template.test new file mode 100644 index 000000000..1992510b2 --- /dev/null +++ b/test/Twig/Tests/Fixtures/exceptions/undefined_template_in_child_template.test @@ -0,0 +1,15 @@ +--TEST-- +Exception for an undefined template in a child template +--TEMPLATE-- +{% extends 'base.twig' %} + +{% block sidebar %} + {{ include('include.twig') }} +{% endblock %} +--TEMPLATE(base.twig)-- +{% block sidebar %} +{% endblock %} +--DATA-- +return array() +--EXCEPTION-- +Twig_Error_Loader: Template "include.twig" is not defined in "index.twig" at line 5.