Skip to content

Commit 7ec2593

Browse files
committed
Fix Error when the trace has Twig file/line information instead of the original PHP info
1 parent 02118c7 commit 7ec2593

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Error/Error.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class Error extends \Exception
4141
private $lineno;
4242
private $rawMessage;
4343
private ?Source $source;
44+
private string $phpFile;
45+
private int $phpLine;
4446

4547
/**
4648
* Constructor.
@@ -55,6 +57,8 @@ public function __construct(string $message, int $lineno = -1, ?Source $source =
5557
{
5658
parent::__construct('', 0, $previous);
5759

60+
$this->phpFile = $this->getFile();
61+
$this->phpLine = $this->getLine();
5862
$this->lineno = $lineno;
5963
$this->source = $source;
6064
$this->rawMessage = $message;
@@ -111,6 +115,8 @@ private function updateRepr(): void
111115
$this->file = $this->source->getPath();
112116
if ($this->lineno > 0) {
113117
$this->line = $this->lineno;
118+
} else {
119+
$this->line = -1;
114120
}
115121
}
116122

@@ -158,8 +164,7 @@ private function guessTemplateInfo(): void
158164

159165
while ($e = array_pop($exceptions)) {
160166
$traces = $e->getTrace();
161-
array_unshift($traces, ['file' => $e->getFile(), 'line' => $e->getLine()]);
162-
167+
array_unshift($traces, ['file' => $e instanceof Error ? $e->phpFile : $e->getFile(), 'line' => $e instanceof Error ? $e->phpLine : $e->getLine()]);
163168
while ($trace = array_shift($traces)) {
164169
if (!isset($trace['file']) || !isset($trace['line']) || $file != $trace['file']) {
165170
continue;

0 commit comments

Comments
 (0)