Skip to content

Commit 0709989

Browse files
authored
Merge pull request #27 from tzurbaev/patch-1
Catch `\Throwable` before `\Exception`
2 parents b919041 + 0624e5f commit 0709989

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

src/Understand/UnderstandLaravel5/ExceptionEncoder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ public function getCode($relativePath, $line, $linesAround = 6)
216216

217217
return $codeLines;
218218
}
219+
catch (\Throwable $e)
220+
{}
219221
catch (\Exception $e)
220222
{}
221223
}

src/Understand/UnderstandLaravel5/FieldProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ protected function getUserId()
431431
return $userId;
432432
}
433433
}
434+
catch (\Throwable $e)
435+
{}
434436
catch (\Exception $e)
435437
{}
436438

@@ -441,6 +443,8 @@ protected function getUserId()
441443
return $user->id;
442444
}
443445
}
446+
catch (\Throwable $e)
447+
{}
444448
catch (\Exception $e)
445449
{}
446450

@@ -451,6 +455,8 @@ protected function getUserId()
451455
return $user->id;
452456
}
453457
}
458+
catch (\Throwable $e)
459+
{}
454460
catch (\Exception $e)
455461
{}
456462
}

src/Understand/UnderstandLaravel5/Logger.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ protected function send(array $event)
153153
{
154154
return $this->handler->handle($event);
155155
}
156+
catch (\Throwable $e)
157+
{
158+
return false;
159+
}
156160
catch (\Exception $ex)
157161
{
158162
return false;

tests/FieldProviderTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testExtend()
2929

3030
$this->assertSame($value, $fieldProvider->{$method}());
3131
}
32-
32+
3333
public function testLaravelAuth()
3434
{
3535
$userId = 23452345;
@@ -71,6 +71,18 @@ public function testSentryGetUser()
7171
$this->assertSame($user->id, $currentUserId);
7272
}
7373

74+
public function testFieldProviderThrowsAnException()
75+
{
76+
$loader = AliasLoader::getInstance();
77+
$loader->alias('Sentry', '\Illuminate\Support\Facades\Auth');
78+
79+
\Illuminate\Support\Facades\Auth::shouldReceive('getUser')->andThrow('Exception');
80+
81+
$currentUserId = $this->app['understand.fieldProvider']->getUserId();
82+
83+
$this->assertNull($currentUserId);
84+
}
85+
7486
public function testQueryCount()
7587
{
7688
$this->app['understand.dataCollector']->set('sql_queries', range(1, 1000));

0 commit comments

Comments
 (0)