From f1e3c98ffcc2d298b0b0f593bc304e57b24131fa Mon Sep 17 00:00:00 2001 From: Glendon Solsberry Date: Fri, 18 Jan 2019 14:53:26 -0500 Subject: [PATCH] Handles cases where the first line might not be the line that matches the regex (#4) * Handles cases where the first line might not be the line that matches the regex * Clean up per request --- src/Stacktrace.php | 2 +- tests/StacktraceTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Stacktrace.php b/src/Stacktrace.php index c910661..99f3e4d 100755 --- a/src/Stacktrace.php +++ b/src/Stacktrace.php @@ -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) { diff --git a/tests/StacktraceTest.php b/tests/StacktraceTest.php index 993399a..d5514bb 100644 --- a/tests/StacktraceTest.php +++ b/tests/StacktraceTest.php @@ -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); + } }