tweaked error message when wrapping an external exception

This commit is contained in:
Fabien Potencier
2011-04-12 15:37:51 +02:00
parent 4d2727f004
commit fbadd66852
3 changed files with 12 additions and 2 deletions
+10
View File
@@ -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)
+1 -1
View File
@@ -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);
}
}
+1 -1
View File
@@ -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());
}