Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
[PROF-411] Handle PHP7 case of Exceptions being string only in Profil…
Browse files Browse the repository at this point in the history
…er::logException:
  • Loading branch information
beberlei committed Jan 4, 2016
1 parent 973136a commit 4275711
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/Tideways/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -793,9 +793,13 @@ public static function logFatal($message, $file, $line, $type = null, $trace = n
));
}

public static function logException(\Exception $exception)
public static function logException($exception)
{
if (self::$error === true || !self::$currentRootSpan) {
if (is_string($exception)) {
$exception = new \RuntimeException($exception);
}

if (self::$error === true || !self::$currentRootSpan || !($exception instanceof \Exception)) {
return;
}

Expand Down
17 changes: 17 additions & 0 deletions tests/Tideways/ProfilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ public function testLogExceptionPassedToTrace()
\Tideways\Profiler::stop();
}

public function testLogExceptionString()
{
$neverProfile = 0;

$backend = self::createBackend();
$backend->expects($this->once())->method('socketStore')->will($this->returnCallback(function($trace) {
$annotations = $trace['spans'][0]['a'];
$this->assertEquals('Error', $annotations['err_msg']);
$this->assertContains('Profiler.php', $annotations['err_source']);
$this->assertEquals('RuntimeException', $annotations['err_exception']);
}));

\Tideways\Profiler::start('foo', $neverProfile);
\Tideways\Profiler::logException("Error");
\Tideways\Profiler::stop();
}

private function createBackend()
{
$backend = $this->getMock('Tideways\Profiler\Backend');
Expand Down

0 comments on commit 4275711

Please sign in to comment.