From fbadd6685206ccd094b5f313fe290294c2dde36e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 12 Apr 2011 15:37:51 +0200 Subject: [PATCH] tweaked error message when wrapping an external exception --- lib/Twig/Error.php | 10 ++++++++++ lib/Twig/Template.php | 2 +- test/Twig/Tests/ErrorTest.php | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) 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()); } -- 1.7.2.5