Skip to content

Commit de48199

Browse files
committed
Merge pull request #3 from dimitrytarasov/master
Add current file/line to exception stack-trace
2 parents 93621cf + b8bbc3d commit de48199

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/Stackify/Log/Entities/ErrorWrapper.php

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

1414
const TYPE_STRING_EXCEPTION = 'StringException';
15+
const UNKNOWN_METHOD = '{unknown}';
1516

1617
/**
1718
* @var \Stackify\Log\Entities\ErrorWrapper
@@ -24,7 +25,12 @@ public function __construct($object, $nestingLevel = 1)
2425
$this->message = $object->getMessage();
2526
$this->type = get_class($object);
2627
$this->code = $object->getCode();
27-
$this->setTrace($object->getTrace());
28+
$trace = $object->getTrace();
29+
$trace[] = array(
30+
'file' => $object->getFile(),
31+
'line' => $object->getLine(),
32+
);
33+
$this->setTrace($trace);
2834
$previous = $object->getPrevious();
2935
if (null !== $previous) {
3036
// limit nesting level if needed here
@@ -80,7 +86,11 @@ private function setTrace(array $trace)
8086
{
8187
$result = array();
8288
foreach ($this->filterTrace($trace) as $index => $item) {
83-
$function = $item['function'] . '()';
89+
if (isset($item['function'])) {
90+
$function = $item['function'] . '()';
91+
} else {
92+
$function = self::UNKNOWN_METHOD;
93+
}
8494
if (isset($item['class'])) {
8595
// type is -> or :: which means dynamic or static method call
8696
$type = isset($item['type']) ? $item['type'] : '->';

src/Stackify/Log/Entities/NativeError.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ public function getTrace()
3737
$traceItem = array(
3838
'file' => $this->file,
3939
'line' => $this->line,
40-
// "method" is not defined in native error
41-
'function' => '{unknown}',
4240
);
4341
return array($traceItem);
4442
}

0 commit comments

Comments
 (0)