Skip to content

Commit

Permalink
Correct handling of fatal errors (fixes getsentryGH-401)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Feb 3, 2017
1 parent 23832e9 commit 621378f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/Raven/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ public function __construct($client, $send_errors_last = false, $error_types = n

$this->client = $client;
$this->error_types = $error_types;
$this->fatal_error_types = array_reduce($this->fatal_error_types, array($this, 'bitwiseOr'));
if ($send_errors_last) {
$this->send_errors_last = true;
$this->client->store_errors_for_bulk_send = true;
}
}

public function bitwiseOr($a, $b)
{
return $a | $b;
}

public function handleException($e, $isError = false, $vars = null)
{
$e->event_id = $this->client->captureException($e, null, null, $vars);
Expand Down Expand Up @@ -119,7 +125,7 @@ public function handleFatalError()
return;
}

if ($error['type'] & $this->fatal_error_types) {
if ($this->shouldCaptureFatalError($error['type'])) {
$e = new ErrorException(
@$error['message'], 0, @$error['type'],
@$error['file'], @$error['line']
Expand All @@ -128,6 +134,11 @@ public function handleFatalError()
}
}

public function shouldCaptureFatalError($type)
{
return $type & $this->fatal_error_types;
}

/**
* Register a handler which will intercept unhnalded exceptions and report them to the
* associated Sentry client.
Expand Down
12 changes: 12 additions & 0 deletions test/Raven/Tests/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ public function testSilentErrorsAreNotReportedWithLocal()
$handler->handleFatalError();
}

public function testShouldCaptureFatalErrorBehavior()
{
$client = $this->getMockBuilder('Client')
->setMethods(array('captureException'))
->getMock();
$handler = new Raven_ErrorHandler($client);

$this->assertEquals($handler->shouldCaptureFatalError(E_ERROR), true);

$this->assertEquals($handler->shouldCaptureFatalError(E_WARNING), false);
}

public function testErrorHandlerDefaultsErrorReporting()
{
$client = $this->getMockBuilder('Client')
Expand Down

0 comments on commit 621378f

Please sign in to comment.