Skip to content

Commit

Permalink
Fix missing source code excerpts for stacktrace frames when the absol…
Browse files Browse the repository at this point in the history
…ute file path is equal to the stripped file path (#1104)

Co-authored-by: Stefano Arlandini <sarlandini@alice.it>
  • Loading branch information
IonBazan and ste93cry committed Oct 5, 2020
1 parent a35c6c7 commit e3d9a02
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Fix missing source code excerpts for stacktrace frames whose absolute file path is equal to the file path (#1104)

## 3.0.2 (2020-10-02)

- fix: Use the traces sample rate for traces instead of the event sample rate (#1106)
Expand Down
2 changes: 1 addition & 1 deletion src/FrameBuilder.php
Expand Up @@ -84,7 +84,7 @@ public function buildFromBacktraceFrame(string $file, int $line, array $backtrac
$strippedFilePath,
$line,
$rawFunctionName,
Frame::INTERNAL_FRAME_FILENAME !== $file && $strippedFilePath !== $file ? $file : null,
Frame::INTERNAL_FRAME_FILENAME !== $file ? $file : null,
$this->getFunctionArguments($backtraceFrame),
$this->isFrameInApp($file, $functionName)
);
Expand Down
2 changes: 1 addition & 1 deletion src/StacktraceBuilder.php
Expand Up @@ -70,7 +70,7 @@ public function buildFromBacktrace(array $backtrace, string $file, int $line): S
}

// Add a final stackframe for the first method ever of this stacktrace
array_unshift($frames, new Frame(null, $file, $line));
array_unshift($frames, $this->frameBuilder->buildFromBacktraceFrame($file, $line, []));

return new Stacktrace($frames);
}
Expand Down
14 changes: 7 additions & 7 deletions tests/FrameBuilderTest.php
Expand Up @@ -36,7 +36,7 @@ public function buildFromBacktraceFrameDataProvider(): \Generator
'line' => 20,
'function' => 'test_function',
],
new Frame('test_function', '/path/to/file', 10),
new Frame('test_function', '/path/to/file', 10, null, '/path/to/file'),
];

yield [
Expand All @@ -46,7 +46,7 @@ public function buildFromBacktraceFrameDataProvider(): \Generator
'line' => 20,
'function' => 'test_function',
],
new Frame('test_function', '/path/to/file', 10),
new Frame('test_function', '/path/to/file', 10, null, '/path/to/file'),
];

yield [
Expand All @@ -57,7 +57,7 @@ public function buildFromBacktraceFrameDataProvider(): \Generator
'function' => 'test_function',
'class' => 'TestClass',
],
new Frame('TestClass::test_function', '/path/to/file', 10, 'TestClass::test_function'),
new Frame('TestClass::test_function', '/path/to/file', 10, 'TestClass::test_function', '/path/to/file'),
];

yield [
Expand All @@ -67,7 +67,7 @@ public function buildFromBacktraceFrameDataProvider(): \Generator
'line' => 10,
'function' => 'test_function',
],
new Frame('test_function', '/path/to/file', 10),
new Frame('test_function', '/path/to/file', 10, null, '/path/to/file'),
];

yield [
Expand All @@ -78,7 +78,7 @@ public function buildFromBacktraceFrameDataProvider(): \Generator
'function' => 'test_function',
'class' => "class@anonymous\0/path/to/file",
],
new Frame("class@anonymous\0/path/to/file::test_function", '/path/to/file', 10, "class@anonymous\0/path/to/file::test_function"),
new Frame("class@anonymous\0/path/to/file::test_function", '/path/to/file', 10, "class@anonymous\0/path/to/file::test_function", '/path/to/file'),
];

yield [
Expand Down Expand Up @@ -133,7 +133,7 @@ public function buildFromBacktraceFrameDataProvider(): \Generator
'file' => 'path/not/of/app/path/to/file',
'line' => 10,
],
new Frame(null, 'path/not/of/app/path/to/file', 10, null),
new Frame(null, 'path/not/of/app/path/to/file', 10, null, 'path/not/of/app/path/to/file'),
];

yield [
Expand All @@ -147,7 +147,7 @@ public function buildFromBacktraceFrameDataProvider(): \Generator
'file' => 'path/not/of/app/to/file',
'line' => 10,
],
new Frame(null, 'path/not/of/app/to/file', 10, null),
new Frame(null, 'path/not/of/app/to/file', 10, null, 'path/not/of/app/to/file'),
];
}

Expand Down
2 changes: 2 additions & 0 deletions tests/StacktraceBuilderTest.php
Expand Up @@ -38,10 +38,12 @@ public function testBuildFromBacktrace(): void

$this->assertNull($frames[0]->getFunctionName());
$this->assertSame('/in/jXVmi', $frames[0]->getFile());
$this->assertSame('/in/jXVmi', $frames[0]->getAbsoluteFilePath());
$this->assertSame(5, $frames[0]->getLine());

$this->assertSame('{closure}', $frames[1]->getFunctionName());
$this->assertSame('/in/jXVmi', $frames[1]->getFile());
$this->assertSame('/in/jXVmi', $frames[1]->getAbsoluteFilePath());
$this->assertSame(9, $frames[1]->getLine());

$this->assertSame('main', $frames[2]->getFunctionName());
Expand Down

0 comments on commit e3d9a02

Please sign in to comment.