Skip to content

Commit f1e3c98

Browse files
gms8994austinkregel
authored andcommitted
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
1 parent 83aa4d9 commit f1e3c98

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Stacktrace.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected function breakUpTheStacks()
137137
$newMessage = $newMessage[0];
138138
preg_match_all(static::REGEX_STACK_MESSAGE, $newMessage, $match);
139139

140-
$this->message = $match[1][0];
140+
$this->message = $match[1][0] ?? $newMessage;
141141
}
142142

143143
$this->brokenMap = array_map(function ($frame) {

tests/StacktraceTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,19 @@ public function testWeCanHandleLaravelBasedExceptions()
9696
$this->assertSame('App\Domain\Service\GitHub->__construct(Object(App\Social))', $firstCodeframe->frame);
9797
$this->assertCount(0, $firstCodeframe->code);
9898
}
99+
100+
public function testWeCanHandlePDOBasedExceptions()
101+
{
102+
$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)";
103+
104+
$array = $this->stacktrace->parse($exceptionString);
105+
$this->assertTrue(is_array($array));
106+
$this->assertTrue(!empty($array));
107+
108+
$firstCodeframe = $array[0];
109+
$this->assertInstanceOf(Codeframe::class, $firstCodeframe);
110+
$this->assertSame('/home/austinkregel/Sites/lager/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php', $firstCodeframe->file);
111+
$this->assertSame('PDOStatement->execute(NULL)', $firstCodeframe->frame);
112+
$this->assertCount(0, $firstCodeframe->code);
113+
}
99114
}

0 commit comments

Comments
 (0)