mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-20 07:43:05 +00:00
Improve error reporting
This commit is contained in:
+9
-24
@@ -106,41 +106,26 @@ class Error extends \Exception
|
||||
|
||||
private function updateRepr(): void
|
||||
{
|
||||
$this->message = $this->rawMessage;
|
||||
|
||||
if ($this->source && $this->source->getPath() && $this->lineno > 0) {
|
||||
$this->file = $this->source->getPath();
|
||||
if ($this->lineno > 0) {
|
||||
$this->line = $this->lineno;
|
||||
|
||||
return;
|
||||
}
|
||||
if ($this->source && $this->source->getPath()) {
|
||||
$this->file = $this->source->getPath();
|
||||
}
|
||||
|
||||
$dot = false;
|
||||
if (str_ends_with($this->message, '.')) {
|
||||
$this->message = $this->rawMessage;
|
||||
$last = substr($this->message, -1);
|
||||
if ($punctuation = '.' === $last || '?' === $last ? $last : '') {
|
||||
$this->message = substr($this->message, 0, -1);
|
||||
$dot = true;
|
||||
}
|
||||
|
||||
$questionMark = false;
|
||||
if (str_ends_with($this->message, '?')) {
|
||||
$this->message = substr($this->message, 0, -1);
|
||||
$questionMark = true;
|
||||
}
|
||||
|
||||
if ($this->source && $this->source->getName()) {
|
||||
$this->message .= \sprintf(' in "%s"', $this->source->getName());
|
||||
}
|
||||
|
||||
if ($this->lineno > 0) {
|
||||
$this->message .= \sprintf(' at line %d', $this->lineno);
|
||||
}
|
||||
|
||||
if ($dot) {
|
||||
$this->message .= '.';
|
||||
}
|
||||
|
||||
if ($questionMark) {
|
||||
$this->message .= '?';
|
||||
if ($punctuation) {
|
||||
$this->message .= $punctuation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -97,7 +97,7 @@ EOHTML,
|
||||
|
||||
$this->fail();
|
||||
} catch (RuntimeError $e) {
|
||||
$this->assertEquals('Variable "foo" does not exist.', $e->getMessage());
|
||||
$this->assertEquals('Variable "foo" does not exist in "index.html" at line 3.', $e->getMessage());
|
||||
$this->assertEquals(3, $e->getTemplateLine());
|
||||
$this->assertEquals('index.html', $e->getSourceContext()->getName());
|
||||
$this->assertEquals(3, $e->getLine());
|
||||
@@ -116,7 +116,7 @@ EOHTML,
|
||||
|
||||
$this->fail();
|
||||
} catch (RuntimeError $e) {
|
||||
$this->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...").', $e->getMessage());
|
||||
$this->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...") in "index.html" at line 3.', $e->getMessage());
|
||||
$this->assertEquals(3, $e->getTemplateLine());
|
||||
$this->assertEquals('index.html', $e->getSourceContext()->getName());
|
||||
$this->assertEquals(3, $e->getLine());
|
||||
|
||||
Reference in New Issue
Block a user