mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 10:56:38 +00:00
tweaked error message when wrapping an external exception
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user