From 9feb12a6f9151cf4f159fdae235947751fe00a29 Mon Sep 17 00:00:00 2001 From: Chris Stone Date: Tue, 8 Dec 2015 19:21:42 -0500 Subject: [PATCH 1/5] Exception type hints to Throwable and renamed variables to reflect --- src/Bugsnag/Client.php | 8 ++++---- src/Bugsnag/Error.php | 6 +++--- tests/Bugsnag/ErrorTest.php | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Bugsnag/Client.php b/src/Bugsnag/Client.php index a9fb71da..620dd2d1 100644 --- a/src/Bugsnag/Client.php +++ b/src/Bugsnag/Client.php @@ -454,9 +454,9 @@ public function setSendCode($sendCode) * @param Array $metaData optional metaData to send with this error * @param String $severity optional severity of this error (fatal/error/warning/info) */ - public function notifyException(Exception $exception, array $metaData = null, $severity = null) + public function notifyException(Throwable $throwable, array $metaData = null, $severity = null) { - $error = Bugsnag_Error::fromPHPException($this->config, $this->diagnostics, $exception); + $error = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $throwable); $error->setSeverity($severity); $this->notify($error, $metaData); @@ -479,13 +479,13 @@ public function notifyError($name, $message, array $metaData = null, $severity = } // Exception handler callback, should only be called internally by PHP's set_exception_handler - public function exceptionHandler($exception) + public function exceptionHandler($throwable) { if(!$this->config->autoNotify) { return; } - $error = Bugsnag_Error::fromPHPException($this->config, $this->diagnostics, $exception); + $error = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $throwable); $error->setSeverity("error"); $this->notify($error); } diff --git a/src/Bugsnag/Error.php b/src/Bugsnag/Error.php index dedd9aa5..77f068ce 100644 --- a/src/Bugsnag/Error.php +++ b/src/Bugsnag/Error.php @@ -30,10 +30,10 @@ public static function fromPHPError(Bugsnag_Configuration $config, Bugsnag_Diagn return $error; } - public static function fromPHPException(Bugsnag_Configuration $config, Bugsnag_Diagnostics $diagnostics, Exception $exception) + public static function fromPHPThrowable(Bugsnag_Configuration $config, Bugsnag_Diagnostics $diagnostics, Throwable $throwable) { $error = new Bugsnag_Error($config, $diagnostics); - $error->setPHPException($exception); + $error->setPHPException($throwable); return $error; } @@ -143,7 +143,7 @@ public function setMetaData($metaData) public function setPrevious($exception) { if ($exception) { - $this->previous = Bugsnag_Error::fromPHPException($this->config, $this->diagnostics, $exception); + $this->previous = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $exception); } return $this; diff --git a/tests/Bugsnag/ErrorTest.php b/tests/Bugsnag/ErrorTest.php index 26ff1160..772bd23c 100644 --- a/tests/Bugsnag/ErrorTest.php +++ b/tests/Bugsnag/ErrorTest.php @@ -105,7 +105,7 @@ public function testPreviousException() if (version_compare(PHP_VERSION, '5.3.0', '>=')) { $exception = new Exception("secondly", 65533, new Exception("firstly")); - $error = Bugsnag_Error::fromPHPException($this->config, $this->diagnostics, $exception); + $error = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $exception); $errorArray = $error->toArray(); From d97ce3cc7fe13d2516438283db5130f98c528675 Mon Sep 17 00:00:00 2001 From: Chris Stone Date: Tue, 22 Dec 2015 15:07:04 -0500 Subject: [PATCH 2/5] Removed Throwable as a type declaration on notifyException and fromPHPThrowable to maintain 5.x compatibility --- src/Bugsnag/Client.php | 2 +- src/Bugsnag/Error.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bugsnag/Client.php b/src/Bugsnag/Client.php index 620dd2d1..2b493d8d 100644 --- a/src/Bugsnag/Client.php +++ b/src/Bugsnag/Client.php @@ -454,7 +454,7 @@ public function setSendCode($sendCode) * @param Array $metaData optional metaData to send with this error * @param String $severity optional severity of this error (fatal/error/warning/info) */ - public function notifyException(Throwable $throwable, array $metaData = null, $severity = null) + public function notifyException($throwable, array $metaData = null, $severity = null) { $error = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $throwable); $error->setSeverity($severity); diff --git a/src/Bugsnag/Error.php b/src/Bugsnag/Error.php index 77f068ce..06c0c8da 100644 --- a/src/Bugsnag/Error.php +++ b/src/Bugsnag/Error.php @@ -30,7 +30,7 @@ public static function fromPHPError(Bugsnag_Configuration $config, Bugsnag_Diagn return $error; } - public static function fromPHPThrowable(Bugsnag_Configuration $config, Bugsnag_Diagnostics $diagnostics, Throwable $throwable) + public static function fromPHPThrowable(Bugsnag_Configuration $config, Bugsnag_Diagnostics $diagnostics, $throwable) { $error = new Bugsnag_Error($config, $diagnostics); $error->setPHPException($throwable); From 66ddb9dbfb542acd06f7f136fe143149863ea69b Mon Sep 17 00:00:00 2001 From: Delisa Mason Date: Wed, 23 Dec 2015 15:57:33 -0500 Subject: [PATCH 3/5] Update API documentation for `notifyException` --- src/Bugsnag/Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bugsnag/Client.php b/src/Bugsnag/Client.php index 2b493d8d..707d4436 100644 --- a/src/Bugsnag/Client.php +++ b/src/Bugsnag/Client.php @@ -448,9 +448,9 @@ public function setSendCode($sendCode) } /** - * Notify Bugsnag of a non-fatal/handled exception + * Notify Bugsnag of a non-fatal/handled throwable * - * @param Exception $exception the exception to notify Bugsnag about + * @param Throwable $throwable the throwable to notify Bugsnag about * @param Array $metaData optional metaData to send with this error * @param String $severity optional severity of this error (fatal/error/warning/info) */ From 95be0af927f82015f1e8f62ce3baeb96450d2000 Mon Sep 17 00:00:00 2001 From: Delisa Mason Date: Wed, 23 Dec 2015 16:26:46 -0500 Subject: [PATCH 4/5] Disallow notifying about non-throwables --- src/Bugsnag/Client.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Bugsnag/Client.php b/src/Bugsnag/Client.php index 707d4436..5b49c97c 100644 --- a/src/Bugsnag/Client.php +++ b/src/Bugsnag/Client.php @@ -456,10 +456,12 @@ public function setSendCode($sendCode) */ public function notifyException($throwable, array $metaData = null, $severity = null) { - $error = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $throwable); - $error->setSeverity($severity); + if (is_subclass_of($throwable, 'Throwable') || is_subclass_of($throwable, 'Exception') || get_class($throwable) == 'Exception') { + $error = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $throwable); + $error->setSeverity($severity); - $this->notify($error, $metaData); + $this->notify($error, $metaData); + } } /** From 23ac8cdd1c06665b06a57a2c4a842729ac9c052e Mon Sep 17 00:00:00 2001 From: Delisa Mason Date: Wed, 23 Dec 2015 16:45:37 -0500 Subject: [PATCH 5/5] [CHANGELOG] Update with PHP7 changes --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3d3895f..03092093 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ Changelog ========= +2.6.0 +----- + +### Enhancements + +* Add support for PHP 7's Throwable + | [Chris Stone](https://github.com/cmstone) + | [#106](https://github.com/bugsnag/bugsnag-php/pull/106) + 2.5.6 ----- - Added a debug flag to help diagnose notification problems