Skip to content

Commit 14464b3

Browse files
committed
Merge pull request php-debugbar#125 from barryvdh/patch-7
Check if the exception file exists.
2 parents aef2c8c + 849231d commit 14464b3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/DebugBar/DataCollector/ExceptionsCollector.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,20 @@ public function collect()
6969
*/
7070
public function formatExceptionData(Exception $e)
7171
{
72-
$lines = file($e->getFile());
73-
$start = $e->getLine() - 4;
74-
$lines = array_slice($lines, $start < 0 ? 0 : $start, 7);
72+
$filePath = $e->getFile();
73+
if ($filePath && file_exists($filePath)) {
74+
$lines = file($filePath);
75+
$start = $e->getLine() - 4;
76+
$lines = array_slice($lines, $start < 0 ? 0 : $start, 7);
77+
} else {
78+
$lines = array("Cannot open the file ($filePath) in which the exception occurred ");
79+
}
7580

7681
return array(
7782
'type' => get_class($e),
7883
'message' => $e->getMessage(),
7984
'code' => $e->getCode(),
80-
'file' => $e->getFile(),
85+
'file' => $filePath,
8186
'line' => $e->getLine(),
8287
'surrounding_lines' => $lines
8388
);

0 commit comments

Comments
 (0)