From: Fabien Potencier Date: Tue, 12 Apr 2011 13:37:51 +0000 (+0200) Subject: tweaked error message when wrapping an external exception X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=fbadd6685206ccd094b5f313fe290294c2dde36e;p=web%2Fkonrad%2Ftwig.git tweaked error message when wrapping an external exception --- diff --git a/lib/Twig/Error.php b/lib/Twig/Error.php index c7c344f..88af6f4 100644 --- a/lib/Twig/Error.php +++ b/lib/Twig/Error.php @@ -115,6 +115,12 @@ class Twig_Error extends Exception { $this->message = $this->rawMessage; + $dot = false; + if ('.' === substr($this->message, -1)) { + $this->message = substr($this->message, 0, -1); + $dot = true; + } + if (null !== $this->filename) { $this->message .= sprintf(' in %s', json_encode($this->filename)); } @@ -122,6 +128,10 @@ class Twig_Error extends Exception if ($this->lineno >= 0) { $this->message .= sprintf(' at line %d', $this->lineno); } + + if ($dot) { + $this->message .= '.'; + } } protected function findTemplateInfo(Exception $e) diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 34556c1..4e1c6f3 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -169,7 +169,7 @@ abstract class Twig_Template implements Twig_TemplateInterface } catch (Twig_Error $e) { throw $e; } catch (Exception $e) { - throw new Twig_Error_Runtime($e->getMessage(), -1, null, $e); + throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, null, $e); } } diff --git a/test/Twig/Tests/ErrorTest.php b/test/Twig/Tests/ErrorTest.php index 3f914a6..7c065b9 100644 --- a/test/Twig/Tests/ErrorTest.php +++ b/test/Twig/Tests/ErrorTest.php @@ -43,7 +43,7 @@ class Twig_Tests_ErrorTest extends Twig_Tests_TestCase $this->fail(); } catch (Twig_Error_Runtime $e) { - $this->assertEquals('Runtime error... in "index" at line 4', $e->getMessage()); + $this->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...") in "index" at line 4.', $e->getMessage()); $this->assertEquals(4, $e->getTemplateLine()); $this->assertEquals('index', $e->getTemplateFile()); }