Skip to content

Commit 15360d6

Browse files
author
dimitrytarasov
committed
In some cases file and line may be undefined in stack-trace
1 parent 945dd33 commit 15360d6

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

src/Stackify/Log/Entities/ErrorWrapper.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ErrorWrapper
1212
private $sourceMethod;
1313

1414
const TYPE_STRING_EXCEPTION = 'StringException';
15-
const UNKNOWN_METHOD = '{unknown}';
15+
const TRACE_UNKNOWN_ITEM = '{unknown}';
1616

1717
/**
1818
* @var \Stackify\Log\Entities\ErrorWrapper
@@ -89,19 +89,23 @@ private function setTrace(array $trace)
8989
if (isset($item['function'])) {
9090
$function = $item['function'] . '()';
9191
} else {
92-
$function = self::UNKNOWN_METHOD;
92+
$function = self::TRACE_UNKNOWN_ITEM;
9393
}
9494
if (isset($item['class'])) {
9595
// type is -> or :: which means dynamic or static method call
96-
$type = isset($item['type']) ? $item['type'] : '->';
96+
$type = $this->getTraceItem($item, 'type', '->');
9797
$function = $item['class'] . $type . $function;
9898
$sourceMethod = $function;
9999
} else {
100-
$sourceMethod = $item['file'] . ':' . $function;
100+
if (isset($item['file'])) {
101+
$sourceMethod = $item['file'] . ':' . $function;
102+
} else {
103+
$sourceMethod = $function;
104+
}
101105
}
102106
$result[] = array(
103-
'file' => $item['file'],
104-
'line' => $item['line'],
107+
'file' => $this->getTraceItem($item, 'file', self::TRACE_UNKNOWN_ITEM),
108+
'line' => $this->getTraceItem($item, 'line', 0),
105109
'function' => $function,
106110
);
107111
if (0 === $index) {
@@ -111,6 +115,11 @@ private function setTrace(array $trace)
111115
$this->trace = $result;
112116
}
113117

118+
private function getTraceItem($item, $keyName, $defaulValue = null)
119+
{
120+
return isset($item[$keyName]) ? $item[$keyName] : $defaulValue;
121+
}
122+
114123
private function filterTrace(array $trace)
115124
{
116125
$filtered = array();

0 commit comments

Comments
 (0)