Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added template file information when an error occurs during compilation

  • Loading branch information...
commit 1e09c7b660856b8178c120328b7a13a371f109e4 1 parent 9d88081
@fabpot authored
Showing with 12 additions and 3 deletions.
  1. +12 −3 lib/Twig/Environment.php
View
15 lib/Twig/Environment.php
@@ -298,11 +298,13 @@ public function loadTemplate($name)
}
if (!class_exists($cls, false)) {
+ $code = $this->compileSource($this->loader->getSource($name), $name);
+
if (false === $cache = $this->getCacheFilename($name)) {
- eval('?>'.$this->compileSource($this->loader->getSource($name), $name));
+ eval('?>'.$code);
} else {
if (!file_exists($cache) || ($this->isAutoReload() && !$this->loader->isFresh($name, filemtime($cache)))) {
- $this->writeCacheFile($cache, $this->compileSource($this->loader->getSource($name), $name));
+ $this->writeCacheFile($cache, $code);
}
require_once $cache;
@@ -459,7 +461,14 @@ public function compile(Twig_NodeInterface $node)
*/
public function compileSource($source, $name = null)
{
- return $this->compile($this->parse($this->tokenize($source, $name)));
+ try {
+ return $this->compile($this->parse($this->tokenize($source, $name)));
+ } catch (Twig_Error $e) {
+ $e->setTemplateFile($name);
+ throw $e;
+ } catch (Exception $e) {
+ throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the compilation of a template ("%s").', $e->getMessage()), -1, $name, $e);
+ }
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.