Skip to content

Commit

Permalink
Fix error when a file from the stacktrace doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jun 27, 2024
1 parent aae7791 commit cbaeb30
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Exceptions/src/Renderer/ConsoleRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/Exceptions/src/Renderer/PlainRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit cbaeb30

Please sign in to comment.