From 3cf357391a243af489c84c4cb2c905a2a89e589a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 5 Jun 2011 12:07:30 +0200 Subject: [PATCH] fixed Twig_Error when the exception is thrown from within the generated template --- lib/Twig/Error.php | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/Twig/Error.php b/lib/Twig/Error.php index 5e6974a..d4abdc4 100644 --- a/lib/Twig/Error.php +++ b/lib/Twig/Error.php @@ -156,16 +156,17 @@ class Twig_Error extends Exception return array($currentLine, $currentFile); } - $trace = $traces[$i - 1]; - if (!isset($trace['line'])) { - $trace['line'] = -log(0); + if (0 === $i) { + $line = $e->getLine(); + } else { + $line = isset($traces[$i - 1]['line']) ? $traces[$i - 1]['line'] : -log(0); } $tokens = token_get_all(file_get_contents($r->getFilename())); $templateline = -1; $template = null; while ($token = array_shift($tokens)) { - if (isset($token[2]) && $token[2] >= $trace['line']) { + if (isset($token[2]) && $token[2] >= $line) { return array($templateline, $template); } -- 1.7.2.5