Skip to content

Commit

Permalink
is_file may trigger error [Closes #572]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 19, 2023
1 parent 10eb446 commit 99bcc14
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/Tracy/BlueScreen/BlueScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private function renderActions(\Throwable $ex): array
$class = $m[2];
if (
!class_exists($class, false) && !interface_exists($class, false) && !trait_exists($class, false)
&& ($file = Helpers::guessClassFile($class)) && !is_file($file)
&& ($file = Helpers::guessClassFile($class)) && !@is_file($file) // @ - may trigger error
) {
[$content, $line] = $this->generateNewFileContents($file, $class);
$actions[] = [
Expand All @@ -257,7 +257,7 @@ private function renderActions(\Throwable $ex): array

if (preg_match('# ([\'"])((?:/|[a-z]:[/\\\\])\w[^\'"]+\.\w{2,5})\1#i', $ex->getMessage(), $m)) {
$file = $m[2];
if (is_file($file)) {
if (@is_file($file)) { // @ - may trigger error
$label = 'open';
$content = '';
$line = 1;
Expand Down Expand Up @@ -509,7 +509,7 @@ function ($m) {
// clickable file name
$msg = preg_replace_callback(
'#([\w\\\\/.:-]+\.(?:php|phpt|phtml|latte|neon))(?|:(\d+)| on line (\d+))?#',
fn($m) => @is_file($m[1])
fn($m) => @is_file($m[1]) // @ - may trigger error
? '<a href="' . Helpers::escapeHtml(Helpers::editorUri($m[1], isset($m[2]) ? (int) $m[2] : null)) . '" class="tracy-editor">' . $m[0] . '</a>'
: $m[0],
$msg,
Expand Down
2 changes: 1 addition & 1 deletion src/Tracy/BlueScreen/assets/section-lastMutedError.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (!$lastError) {
<h3><?= Helpers::errorTypeToString($lastError['type']) ?>: <?= Helpers::escapeHtml($lastError['message']) ?></h3>
<p><i>Note: the last muted error may have nothing to do with the thrown exception.</i></p>

<?php if (isset($lastError['file']) && is_file($lastError['file'])): ?>
<?php if (isset($lastError['file']) && @is_file($lastError['file'])): // @ - may trigger error ?>
<p><?= Helpers::editorLink($lastError['file'], $lastError['line']) ?></p>
<div><?= BlueScreen::highlightFile($lastError['file'], $lastError['line']) ?></div>
<?php else: ?>
Expand Down
6 changes: 3 additions & 3 deletions src/Tracy/BlueScreen/assets/section-stack-callStack.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ if (!$stack) {
<div class="tracy-section-panel">
<div class="tracy-callstack">
<?php foreach ($stack as $key => $row): ?>
<?php $clickable = !empty($row['args']) || (isset($row['file']) && is_file($row['file'])) ?>
<?php $clickable = !empty($row['args']) || (isset($row['file']) && @is_file($row['file'])) // @ - may trigger error ?>

<div class="tracy-callstack-file">
<?php if (isset($row['file']) && is_file($row['file'])): ?>
<?php if (isset($row['file']) && @is_file($row['file'])): // @ - may trigger error ?>
<?= Helpers::editorLink($row['file'], $row['line']) ?>
<?php else: ?>
<i>inner-code</i><?php if (isset($row['line'])) echo ':', $row['line'] ?>
Expand All @@ -42,7 +42,7 @@ if (!$stack) {

<?php if ($clickable): ?>
<div class="tracy-callstack-additional<?php if ($expanded !== $key) echo ' tracy-collapsed' ?>">
<?php $sourceOriginal = isset($row['file']) && is_file($row['file']) ? [$row['file'], $row['line']] : null ?>
<?php $sourceOriginal = isset($row['file']) && @is_file($row['file']) ? [$row['file'], $row['line']] : null // @ - may trigger error ?>
<?php $sourceMapped = $sourceOriginal ? Debugger::mapSource(...$sourceOriginal) : null ?>
<?php if ($sourceOriginal && $sourceMapped): ?>
<div class="tracy-tabs">
Expand Down
2 changes: 1 addition & 1 deletion src/Tracy/BlueScreen/assets/section-stack-sourceFile.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Tracy;
* @var int $expanded
*/

$sourceOriginal = $file && is_file($file) ? [$file, $line] : null;
$sourceOriginal = $file && @is_file($file) ? [$file, $line] : null; // @ - may trigger error
$sourceMapped = $sourceOriginal ? Debugger::mapSource($file, $line) : null;
?>

Expand Down
2 changes: 1 addition & 1 deletion src/Tracy/Dumper/Describer.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ private static function findLocation(): ?array
break;
}

if (isset($location['file'], $location['line']) && is_file($location['file'])) {
if (isset($location['file'], $location['line']) && @is_file($location['file'])) { // @ - may trigger error
$lines = file($location['file']);
$line = $lines[$location['line'] - 1];
return [
Expand Down
2 changes: 1 addition & 1 deletion src/Tracy/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function editorUri(
string $replace = '',
): ?string
{
if (Debugger::$editor && $file && ($action === 'create' || is_file($file))) {
if (Debugger::$editor && $file && ($action === 'create' || @is_file($file))) { // @ - may trigger error
$file = strtr($file, '/', DIRECTORY_SEPARATOR);
$file = strtr($file, Debugger::$editorMapping);
$search = str_replace("\n", PHP_EOL, $search);
Expand Down

0 comments on commit 99bcc14

Please sign in to comment.