Skip to content

Commit 98b664a

Browse files
committed
bug #4688 Avoid errors when failing to guess the template info for an error (stof)
This PR was merged into the 3.x branch. Discussion ---------- Avoid errors when failing to guess the template info for an error Someone reported on the Symfony Slack a case where they get a TypeError in `new \ReflectionObject($template)` in the guessing logic instead of seeing the original error they have (the one for which guessing was attempted), making it impossible to know the original error: https://symfony-devs.slack.com/archives/C01FN4EQNLX/p1756762972076319?thread_ts=1756753204.711889&cid=C01FN4EQNLX I don't have a reproducer for that case (the original case involve a Symfony form theme, where the form renderer does weird usages of Twig which might lead to the backtrace not containing the expected template). Not guessing the template file path and the original template line is better than breaking the error reporting. Commits ------- 62747ce Avoid errors when failing to guess the template info for an error
2 parents 8832f63 + 62747ce commit 98b664a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Error/Error.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ private function guessTemplateInfo(): void
148148
}
149149
}
150150

151+
if (null === $template) {
152+
return; // Impossible to guess the info as the template was not found in the backtrace
153+
}
154+
151155
$r = new \ReflectionObject($template);
152156
$file = $r->getFileName();
153157

0 commit comments

Comments
 (0)