mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 11:56:50 +00:00
bug #2700 Report the proper location for errors compiled in templates (stof)
This PR was merged into the 2.x branch.
Discussion
----------
Report the proper location for errors compiled in templates
The `{% use %}` and `{% with %}` tags are adding some runtime checks triggering exceptions in the compiled template. This ensures that they get the proper location.
While the guessing was generally working fine for the `{% with %}` (and so this only makes the code faster), the guessing was not working for `{% use %}` due to the exception happening in the class constructor rather than on display (and so the guessing was finding the template which was triggering the load of the faulty template).
Commits
-------
e4423576 Report the proper location for errors compiled in templates
This commit is contained in:
@@ -198,7 +198,9 @@ class Twig_Node_Module extends Twig_Node
|
||||
->indent()
|
||||
->write("throw new Twig_Error_Runtime('Template \"'.")
|
||||
->subcompile($trait->getNode('template'))
|
||||
->raw(".'\" cannot be used as a trait.');\n")
|
||||
->raw(".'\" cannot be used as a trait.', ")
|
||||
->repr($node->getTemplateLine())
|
||||
->raw(", \$this->source);\n")
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
->write(sprintf("\$_trait_%s_blocks = \$_trait_%s->getBlocks();\n\n", $i, $i))
|
||||
@@ -210,11 +212,13 @@ class Twig_Node_Module extends Twig_Node
|
||||
->string($key)
|
||||
->raw("])) {\n")
|
||||
->indent()
|
||||
->write("throw new Twig_Error_Runtime(sprintf('Block ")
|
||||
->write("throw new Twig_Error_Runtime('Block ")
|
||||
->string($key)
|
||||
->raw(' is not defined in trait ')
|
||||
->subcompile($trait->getNode('template'))
|
||||
->raw(".'));\n")
|
||||
->raw(".', ")
|
||||
->repr($node->getTemplateLine())
|
||||
->raw(", \$this->source);\n")
|
||||
->outdent()
|
||||
->write("}\n\n")
|
||||
|
||||
|
||||
@@ -38,7 +38,9 @@ class Twig_Node_With extends Twig_Node
|
||||
->raw(";\n")
|
||||
->write(sprintf("if (!is_array(\$%s)) {\n", $varsName))
|
||||
->indent()
|
||||
->write("throw new Twig_Error_Runtime('Variables passed to the \"with\" tag must be a hash.');\n")
|
||||
->write("throw new Twig_Error_Runtime('Variables passed to the \"with\" tag must be a hash.', ")
|
||||
->repr($this->getTemplateLine())
|
||||
->raw(", \$this->source);\n")
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user