From cbaeb30b74b74ffc4f710fe5cf5ebc6162ff0e3b Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Fri, 28 Jun 2024 00:02:02 +0400 Subject: [PATCH] Fix error when a file from the stacktrace doesn't exist --- src/Exceptions/src/Renderer/ConsoleRenderer.php | 4 +++- src/Exceptions/src/Renderer/PlainRenderer.php | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Exceptions/src/Renderer/ConsoleRenderer.php b/src/Exceptions/src/Renderer/ConsoleRenderer.php index 25487b378..52a92b497 100644 --- a/src/Exceptions/src/Renderer/ConsoleRenderer.php +++ b/src/Exceptions/src/Renderer/ConsoleRenderer.php @@ -202,11 +202,13 @@ private function renderTrace(\Throwable $e, Highlighter $h = null): string $result .= $line . "\n"; if ($h !== null && !empty($trace['file'])) { + $str = @\file_get_contents($trace['file']); $result .= $h->highlightLines( - \file_get_contents($trace['file']), + $str, $trace['line'], static::SHOW_LINES ) . "\n"; + unset($str); } } diff --git a/src/Exceptions/src/Renderer/PlainRenderer.php b/src/Exceptions/src/Renderer/PlainRenderer.php index b3215b8ff..d082f2c60 100644 --- a/src/Exceptions/src/Renderer/PlainRenderer.php +++ b/src/Exceptions/src/Renderer/PlainRenderer.php @@ -102,12 +102,14 @@ private function renderTrace(\Throwable $e, Highlighter $h = null): string $result .= $line . "\n"; - if ($h !== null && !empty($trace['file'])) { + if ($h !== null && !empty($trace['file']) && \is_file($trace['file'])) { + $str = @\file_get_contents($trace['file']); $result .= $h->highlightLines( - \file_get_contents($trace['file']), + $str, $trace['line'], self::SHOW_LINES ) . "\n"; + unset($str); } }