Skip to content

Commit

Permalink
Handles cases where the first line might not be the line that matches…
Browse files Browse the repository at this point in the history
… the regex (#4)

* Handles cases where the first line might not be the line that matches the regex

* Clean up per request
  • Loading branch information
gms8994 authored and austinkregel committed Jan 18, 2019
1 parent 83aa4d9 commit f1e3c98
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Stacktrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected function breakUpTheStacks()
$newMessage = $newMessage[0];
preg_match_all(static::REGEX_STACK_MESSAGE, $newMessage, $match);

$this->message = $match[1][0];
$this->message = $match[1][0] ?? $newMessage;
}

$this->brokenMap = array_map(function ($frame) {
Expand Down
15 changes: 15 additions & 0 deletions tests/StacktraceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,19 @@ public function testWeCanHandleLaravelBasedExceptions()
$this->assertSame('App\Domain\Service\GitHub->__construct(Object(App\Social))', $firstCodeframe->frame);
$this->assertCount(0, $firstCodeframe->code);
}

public function testWeCanHandlePDOBasedExceptions()
{
$exceptionString = "PDOException: SQLSTATE[22008]: Datetime field overflow: 7 ERROR: date/time field value out of range: \"1967-12-0\"\nHINT: Perhaps you need a different \"datestyle\" setting. in /home/austinkregel/Sites/lager/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:142\nStack trace:\n#0 /home/austinkregel/Sites/lager/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php(142): PDOStatement->execute(NULL)\n#1 /home/austinkregel/Sites/lager/vendor/laravel/framework/src/Illuminate/Database/Connection.php(330): Doctrine\DBAL\Driver\PDOStatement->execute()\n#2 /home/austinkregel/Sites/lager/vendor/laravel/framework/src/Illuminate/Database/Connection.php(657): Illuminate\Database\Connection->Illuminate\Database\{closure}('insert into \"ta...', Array)";

$array = $this->stacktrace->parse($exceptionString);
$this->assertTrue(is_array($array));
$this->assertTrue(!empty($array));

$firstCodeframe = $array[0];
$this->assertInstanceOf(Codeframe::class, $firstCodeframe);
$this->assertSame('/home/austinkregel/Sites/lager/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php', $firstCodeframe->file);
$this->assertSame('PDOStatement->execute(NULL)', $firstCodeframe->frame);
$this->assertCount(0, $firstCodeframe->code);
}
}

0 comments on commit f1e3c98

Please sign in to comment.