From 621378f8ad2b5579dd8e4883d52abaef0126a513 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Thu, 2 Feb 2017 23:21:09 -0800 Subject: [PATCH] Correct handling of fatal errors (fixes GH-401) --- lib/Raven/ErrorHandler.php | 13 ++++++++++++- test/Raven/Tests/ErrorHandlerTest.php | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/Raven/ErrorHandler.php b/lib/Raven/ErrorHandler.php index 77954ab9c..98223f952 100644 --- a/lib/Raven/ErrorHandler.php +++ b/lib/Raven/ErrorHandler.php @@ -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); @@ -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'] @@ -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. diff --git a/test/Raven/Tests/ErrorHandlerTest.php b/test/Raven/Tests/ErrorHandlerTest.php index d6e8890ab..5d9ee4ba6 100644 --- a/test/Raven/Tests/ErrorHandlerTest.php +++ b/test/Raven/Tests/ErrorHandlerTest.php @@ -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')