From 7bb9b92ba256282af8047a98c43c627766bdbab9 Mon Sep 17 00:00:00 2001 From: ovaldi <232280074@qq.com> Date: Mon, 30 Oct 2017 15:45:18 +0800 Subject: [PATCH 01/10] Bugfix: Raven_CurlHandler -> join_timeout --- lib/Raven/CurlHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Raven/CurlHandler.php b/lib/Raven/CurlHandler.php index 0412a86ba..bcdd632e2 100644 --- a/lib/Raven/CurlHandler.php +++ b/lib/Raven/CurlHandler.php @@ -27,7 +27,7 @@ public function __construct($options, $join_timeout = 5) $this->options = $options; $this->multi_handle = curl_multi_init(); $this->requests = array(); - $this->join_timeout = 5; + $this->join_timeout = $join_timeout; register_shutdown_function(array($this, 'join')); } From 790d621aac84c16b7eb7fa903f65252d8fe35a2b Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Mon, 30 Oct 2017 09:36:42 +0100 Subject: [PATCH 02/10] Changes for 1.9.x dev (#509) * 1.8.0 * Update files for next release --- CHANGELOG.md | 4 ++++ README.md | 14 +++++++------- composer.json | 2 +- lib/Raven/Client.php | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eaaa30c33..2eab5656f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +- ... + +## 1.8.0 (2017-10-29) + - Use namespaced classes in test for PHPUnit (#506) - Prevent segmentation fault on PHP `<5.6` (#504) - Remove `ini_set` call for unneeded functionality (#501) diff --git a/README.md b/README.md index e9917a266..2f9366039 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ Tagging a Release 2. Create a new branch for the minor version (if not present): ``` -$ git checkout -b releases/1.7.x +$ git checkout -b releases/1.9.x ``` 3. Update the hardcoded version tag in ``Client.php``: @@ -106,20 +106,20 @@ $ git checkout -b releases/1.7.x ``` class Raven_Client { - const VERSION = '1.7.0'; + const VERSION = '1.9.0'; } ``` 4. Commit the change: ``` -$ git commit -a -m "1.7.0" +$ git commit -a -m "1.9.0" ``` 5. Tag the branch: ``` -git tag 1.7.0 +git tag 1.9.0 ``` 6. Push the tag: @@ -137,7 +137,7 @@ git checkout master 8. Add the next minor release to the ``CHANGES`` file: ``` -## 1.8.0 (unreleased) +## 1.10.0 (unreleased) ``` 9. Update the version in ``Client.php``: @@ -145,7 +145,7 @@ git checkout master ``` class Raven_Client { - const VERSION = '1.8.x-dev'; + const VERSION = '1.10.x-dev'; } ``` @@ -154,7 +154,7 @@ class Raven_Client ``` "extra": { "branch-alias": { - "dev-master": "1.8.x-dev" + "dev-master": "1.10.x-dev" } } ``` diff --git a/composer.json b/composer.json index cb64a9053..e250dcd8c 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.8.x-dev" + "dev-master": "1.9.x-dev" } } } diff --git a/lib/Raven/Client.php b/lib/Raven/Client.php index ea579147c..5e863b995 100644 --- a/lib/Raven/Client.php +++ b/lib/Raven/Client.php @@ -16,7 +16,7 @@ class Raven_Client { - const VERSION = '1.8.x-dev'; + const VERSION = '1.9.x-dev'; const PROTOCOL = '6'; From 0baca06aa08bb622338deb000cad7ffa2a258e29 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Wed, 8 Nov 2017 11:55:35 +0100 Subject: [PATCH 03/10] Do not capture E_ERROR as fatal error on PHP 7.0+ --- lib/Raven/ErrorHandler.php | 7 +++++++ test/Raven/Tests/ErrorHandlerTest.php | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Raven/ErrorHandler.php b/lib/Raven/ErrorHandler.php index 21358c1ad..01d19500a 100644 --- a/lib/Raven/ErrorHandler.php +++ b/lib/Raven/ErrorHandler.php @@ -140,6 +140,13 @@ public function handleFatalError() public function shouldCaptureFatalError($type) { + // Do not capture E_ERROR since those can be caught by userland since PHP 7.0 + // E_ERROR should already be handled by the exception handler + // This prevents duplicated exceptions in PHP 7.0+ + if (version_compare(phpversion(), '7.0', '>=') && $type === E_ERROR) { + return false; + } + return $type & $this->fatal_error_types; } diff --git a/test/Raven/Tests/ErrorHandlerTest.php b/test/Raven/Tests/ErrorHandlerTest.php index 367bc6aec..3fbd4ee45 100644 --- a/test/Raven/Tests/ErrorHandlerTest.php +++ b/test/Raven/Tests/ErrorHandlerTest.php @@ -207,7 +207,7 @@ public function testShouldCaptureFatalErrorBehavior() ->getMock(); $handler = new Raven_ErrorHandler($client); - $this->assertEquals($handler->shouldCaptureFatalError(E_ERROR), true); + $this->assertEquals($handler->shouldCaptureFatalError(E_ERROR), !version_compare(phpversion(), '7.0', '>=')); $this->assertEquals($handler->shouldCaptureFatalError(E_WARNING), false); } From 13a0a390645f04b7721e6068a4901191dfcfbff5 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Wed, 8 Nov 2017 12:52:23 +0100 Subject: [PATCH 04/10] Add Throwable in the PHPDoc as excepted exception --- lib/Raven/Client.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Raven/Client.php b/lib/Raven/Client.php index 5e863b995..832c9646d 100644 --- a/lib/Raven/Client.php +++ b/lib/Raven/Client.php @@ -561,10 +561,10 @@ public function captureMessage($message, $params = array(), $data = array(), /** * Log an exception to sentry * - * @param Exception $exception The Exception object. - * @param array $data Additional attributes to pass with this event (see Sentry docs). - * @param mixed $logger - * @param mixed $vars + * @param \Throwable|\Exception $exception The Throwable/Exception object. + * @param array $data Additional attributes to pass with this event (see Sentry docs). + * @param mixed $logger + * @param mixed $vars * @return string|null */ public function captureException($exception, $data = null, $logger = null, $vars = null) From fd879a347d922f8812399d9604662942de07bb7b Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Wed, 8 Nov 2017 13:16:53 +0100 Subject: [PATCH 05/10] Test for PHP version using PHP_VERSION_ID --- lib/Raven/Client.php | 4 ++-- lib/Raven/Compat.php | 4 ++-- lib/Raven/ErrorHandler.php | 2 +- test/Raven/Tests/ErrorHandlerTest.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Raven/Client.php b/lib/Raven/Client.php index 832c9646d..25b21a461 100644 --- a/lib/Raven/Client.php +++ b/lib/Raven/Client.php @@ -569,7 +569,7 @@ public function captureMessage($message, $params = array(), $data = array(), */ public function captureException($exception, $data = null, $logger = null, $vars = null) { - $has_chained_exceptions = version_compare(PHP_VERSION, '5.3.0', '>='); + $has_chained_exceptions = PHP_VERSION_ID >= 50300; if (in_array(get_class($exception), $this->exclude)) { return null; @@ -1328,7 +1328,7 @@ public function translateSeverity($severity) case E_STRICT: return Raven_Client::INFO; case E_RECOVERABLE_ERROR: return Raven_Client::ERROR; } - if (version_compare(PHP_VERSION, '5.3.0', '>=')) { + if (PHP_VERSION_ID >= 50300) { switch ($severity) { case E_DEPRECATED: return Raven_Client::WARN; case E_USER_DEPRECATED: return Raven_Client::WARN; diff --git a/lib/Raven/Compat.php b/lib/Raven/Compat.php index 4d5f719aa..1571bae7c 100644 --- a/lib/Raven/Compat.php +++ b/lib/Raven/Compat.php @@ -81,9 +81,9 @@ public static function _hash_hmac($algo, $data, $key, $raw_output = false) public static function json_encode($value, $options = 0, $depth = 512) { if (function_exists('json_encode')) { - if (version_compare(PHP_VERSION, '5.3.0', '<')) { + if (PHP_VERSION_ID < 50300) { return json_encode($value); - } elseif (version_compare(PHP_VERSION, '5.5.0', '<')) { + } elseif (PHP_VERSION_ID < 50500) { return json_encode($value, $options); } else { return json_encode($value, $options, $depth); diff --git a/lib/Raven/ErrorHandler.php b/lib/Raven/ErrorHandler.php index 01d19500a..54e8984d2 100644 --- a/lib/Raven/ErrorHandler.php +++ b/lib/Raven/ErrorHandler.php @@ -143,7 +143,7 @@ public function shouldCaptureFatalError($type) // Do not capture E_ERROR since those can be caught by userland since PHP 7.0 // E_ERROR should already be handled by the exception handler // This prevents duplicated exceptions in PHP 7.0+ - if (version_compare(phpversion(), '7.0', '>=') && $type === E_ERROR) { + if (PHP_VERSION_ID >= 70000 && $type === E_ERROR) { return false; } diff --git a/test/Raven/Tests/ErrorHandlerTest.php b/test/Raven/Tests/ErrorHandlerTest.php index 3fbd4ee45..c19b02b91 100644 --- a/test/Raven/Tests/ErrorHandlerTest.php +++ b/test/Raven/Tests/ErrorHandlerTest.php @@ -207,7 +207,7 @@ public function testShouldCaptureFatalErrorBehavior() ->getMock(); $handler = new Raven_ErrorHandler($client); - $this->assertEquals($handler->shouldCaptureFatalError(E_ERROR), !version_compare(phpversion(), '7.0', '>=')); + $this->assertEquals($handler->shouldCaptureFatalError(E_ERROR), PHP_VERSION_ID < 70000); $this->assertEquals($handler->shouldCaptureFatalError(E_WARNING), false); } From e0d04bc603074934a51da3b2c012275aa394aadc Mon Sep 17 00:00:00 2001 From: Tuzlukov Anton Date: Wed, 8 Nov 2017 17:28:54 +0300 Subject: [PATCH 06/10] Add setters for Raven Serializes --- lib/Raven/Client.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/Raven/Client.php b/lib/Raven/Client.php index 5e863b995..5269e6354 100644 --- a/lib/Raven/Client.php +++ b/lib/Raven/Client.php @@ -44,7 +44,13 @@ class Raven_Client protected $error_handler; protected $error_types; + /** + * @var Raven_Serializer + */ protected $serializer; + /** + * @var Raven_ReprSerializer + */ protected $reprSerializer; /** @@ -1447,4 +1453,20 @@ public function close_curl_resource() $this->_curl_instance = null; } } + + /** + * @param Raven_Serializer $serializer + */ + public function setSerializer(Raven_Serializer $serializer) + { + $this->serializer = $serializer; + } + + /** + * @param Raven_ReprSerializer $reprSerializer + */ + public function setReprSerializer(Raven_ReprSerializer $reprSerializer) + { + $this->reprSerializer = $reprSerializer; + } } From 4913c1f02701c88b47cd9ed9762f0ca8e27fb9fb Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Thu, 9 Nov 2017 09:55:30 +0100 Subject: [PATCH 07/10] Test for PHP version using PHP_VERSION_ID in tests --- test/Raven/Tests/ClientTest.php | 16 +++++++--------- test/Raven/Tests/StacktraceTest.php | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/test/Raven/Tests/ClientTest.php b/test/Raven/Tests/ClientTest.php index 6982f54a0..cd09825c9 100644 --- a/test/Raven/Tests/ClientTest.php +++ b/test/Raven/Tests/ClientTest.php @@ -586,7 +586,7 @@ public function testCaptureExceptionSetsInterfaces() */ public function testCaptureExceptionChainedException() { - if (version_compare(PHP_VERSION, '5.3.0', '<')) { + if (PHP_VERSION_ID < 50300) { $this->markTestSkipped('PHP 5.3 required for chained exceptions.'); } @@ -610,7 +610,7 @@ public function testCaptureExceptionChainedException() */ public function testCaptureExceptionDifferentLevelsInChainedExceptionsBug() { - if (version_compare(PHP_VERSION, '5.3.0', '<')) { + if (PHP_VERSION_ID < 50300) { $this->markTestSkipped('PHP 5.3 required for chained exceptions.'); } @@ -1600,7 +1600,7 @@ public function testTranslateSeverity() $predefined = array(E_ERROR, E_WARNING, E_PARSE, E_NOTICE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, E_STRICT, E_RECOVERABLE_ERROR, ); - if (version_compare(PHP_VERSION, '5.3.0', '>=')) { + if (PHP_VERSION_ID >= 50300) { $predefined[] = E_DEPRECATED; $predefined[] = E_USER_DEPRECATED; } @@ -1769,7 +1769,7 @@ public function testEncodeTooDepth() $data_broken = array($data_broken); } $value = $client->encode($data_broken); - if (!function_exists('json_encode') or version_compare(PHP_VERSION, '5.5.0', '>=')) { + if (!function_exists('json_encode') or PHP_VERSION_ID >= 50500) { $this->assertFalse($value, 'Broken data encoded successfully with '. (function_exists('json_encode') ? 'native method' : 'Raven_Compat::_json_encode')); } else { @@ -1817,11 +1817,9 @@ public function testRegisterDefaultBreadcrumbHandlers() $debug_backtrace = $this->_debug_backtrace; set_error_handler($previous, E_ALL); $this->assertTrue($u); - if (isset($debug_backtrace[1]['function']) and ($debug_backtrace[1]['function'] == 'call_user_func') - and version_compare(PHP_VERSION, '7.0', '>=') - ) { + if (isset($debug_backtrace[1]['function']) and ($debug_backtrace[1]['function'] == 'call_user_func') and PHP_VERSION_ID >= 70000) { $offset = 2; - } elseif (version_compare(PHP_VERSION, '7.0', '>=')) { + } elseif (PHP_VERSION_ID >= 70000) { $offset = 1; } else { $offset = 2; @@ -2048,7 +2046,7 @@ public function testGet_user_data_step1() */ public function testGet_user_data_step2() { - if (version_compare(PHP_VERSION, '7.1.999', '>')) { + if (PHP_VERSION_ID >= 70200) { /** * @doc https://3v4l.org/OVbja * @doc https://3v4l.org/uT00O diff --git a/test/Raven/Tests/StacktraceTest.php b/test/Raven/Tests/StacktraceTest.php index 5bb18d2eb..40b27deaf 100644 --- a/test/Raven/Tests/StacktraceTest.php +++ b/test/Raven/Tests/StacktraceTest.php @@ -124,7 +124,7 @@ public function testDoesFixFrameInfo() // just grab the last few frames $frames = array_slice($frames, -6); $skip_call_user_func_fix = false; - if (version_compare(PHP_VERSION, '7.0', '>=')) { + if (PHP_VERSION_ID >= 70000) { $skip_call_user_func_fix = true; foreach ($frames as &$frame) { if (isset($frame['function']) and ($frame['function'] == 'call_user_func')) { From 498f3f00afd375fe282e53da32077e37ad7744e8 Mon Sep 17 00:00:00 2001 From: Tuzlukov Anton Date: Thu, 9 Nov 2017 15:28:13 +0300 Subject: [PATCH 08/10] test for serialize setters --- test/Raven/Tests/ClientTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/Raven/Tests/ClientTest.php b/test/Raven/Tests/ClientTest.php index 6982f54a0..34bb2c451 100644 --- a/test/Raven/Tests/ClientTest.php +++ b/test/Raven/Tests/ClientTest.php @@ -1437,6 +1437,8 @@ public function testUuid4() * @covers Raven_Client::getLastEventID * @covers Raven_Client::get_extra_data * @covers Raven_Client::setProcessors + * @covers Raven_Client::setSerializer + * @covers Raven_Client::setReprSerializer * @covers Raven_Client::getLastSentryError * @covers Raven_Client::getShutdownFunctionHasBeenSet */ @@ -1447,6 +1449,9 @@ public function testGettersAndSetters() $property_method__convert_path->setAccessible(true); $callable = array($this, 'stabClosureVoid'); + $serializer = $this->getMockBuilder('Raven_Serializer')->getMock(); + $reprSerializer = $this->getMockBuilder('Raven_ReprSerializer')->getMock(); + $data = array( array('environment', null, 'value', ), array('environment', null, null, ), @@ -1476,6 +1481,8 @@ public function testGettersAndSetters() array('extra_data', '_extra_data', array('key' => 'value'), ), array('processors', 'processors', array(), ), array('processors', 'processors', array('key' => 'value'), ), + array('serializer', 'Serializer', $serializer, ), + array('reprSerializer', 'ReprSerializer', $reprSerializer, ), array('_shutdown_function_has_been_set', null, true), array('_shutdown_function_has_been_set', null, false), ); From 2a640cf6d1463f15b6e63a6c456964e2f7018c99 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Thu, 9 Nov 2017 14:17:22 +0100 Subject: [PATCH 09/10] Update CHANGELOG.md (#516) Add informations about #514 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2eab5656f..b10ac4161 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- ... +- Avoid to capture `E_ERROR` in PHP 7+, because it's also a `Throwable` that gets captured and duplicates the error (#514) ## 1.8.0 (2017-10-29) From 976b14ce12a6c9bd49a5f4d3b9882313cb56352e Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Thu, 9 Nov 2017 16:02:14 +0100 Subject: [PATCH 10/10] Prepare changelog for 1.8.1 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b10ac4161..4ecc88ae4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +- ... + +## 1.8.1 (2017-11-09) + +- Add setters for the serializers on the `Raven_Client` (#515) - Avoid to capture `E_ERROR` in PHP 7+, because it's also a `Throwable` that gets captured and duplicates the error (#514) ## 1.8.0 (2017-10-29)