tweaked Twig_Error to keep the passed line or template when passed in the constructor...
authorFabien Potencier <fabien.potencier@gmail.com>
Fri, 22 Apr 2011 14:06:50 +0000 (16:06 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Fri, 22 Apr 2011 14:06:50 +0000 (16:06 +0200)
lib/Twig/Error.php

index 4064652..61dda79 100644 (file)
@@ -33,7 +33,7 @@ class Twig_Error extends Exception
     public function __construct($message, $lineno = -1, $filename = null, Exception $previous = null)
     {
         if (-1 === $lineno || null === $filename) {
-            list($lineno, $filename) = $this->findTemplateInfo(null !== $previous ? $previous : $this);
+            list($lineno, $filename) = $this->findTemplateInfo(null !== $previous ? $previous : $this, $lineno, $filename);
         }
 
         $this->lineno = $lineno;
@@ -134,10 +134,10 @@ class Twig_Error extends Exception
         }
     }
 
-    protected function findTemplateInfo(Exception $e)
+    protected function findTemplateInfo(Exception $e, $currentLine, $currentFile)
     {
         if (!function_exists('token_get_all')) {
-            return array(-1, null);
+            return array($currentLine, $currentFile);
         }
 
         $traces = $e->getTrace();
@@ -153,7 +153,7 @@ class Twig_Error extends Exception
 
             if (!file_exists($r->getFilename())) {
                 // probably an eval()'d code
-                return array(-1, null);
+                return array($currentLine, $currentFile);
             }
 
             $trace = $traces[$i - 1];
@@ -176,9 +176,9 @@ class Twig_Error extends Exception
                 }
             }
 
-            return array(-1, $template);
+            return array($currentLine, $template);
         }
 
-        return array(-1, null);
+        return array($currentLine, $currentFile);
     }
 }