From f3f229ef7cc41aa6dda6bb9e512122c72e12e64c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 4 Aug 2018 14:51:26 +0100 Subject: [PATCH 1/2] Internet: only catch InternetExceptions - anything else is an unexpected fault condition --- src/pocketmine/scheduler/BulkCurlTask.php | 5 +++-- src/pocketmine/utils/Internet.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/scheduler/BulkCurlTask.php b/src/pocketmine/scheduler/BulkCurlTask.php index d7a0e4b39..10270816f 100644 --- a/src/pocketmine/scheduler/BulkCurlTask.php +++ b/src/pocketmine/scheduler/BulkCurlTask.php @@ -24,11 +24,12 @@ declare(strict_types=1); namespace pocketmine\scheduler; use pocketmine\utils\Internet; +use pocketmine\utils\InternetException; /** * Executes a consecutive list of cURL operations. * - * The result of this AsyncTask is an array of arrays (returned from {@link Utils::simpleCurl}) or RuntimeException objects. + * The result of this AsyncTask is an array of arrays (returned from {@link Utils::simpleCurl}) or InternetException objects. * * @package pocketmine\scheduler */ @@ -56,7 +57,7 @@ class BulkCurlTask extends AsyncTask{ foreach($operations as $op){ try{ $results[] = Internet::simpleCurl($op["page"], $op["timeout"] ?? 10, $op["extraHeaders"] ?? [], $op["extraOpts"] ?? []); - }catch(\RuntimeException $e){ + }catch(InternetException $e){ $results[] = $e; } } diff --git a/src/pocketmine/utils/Internet.php b/src/pocketmine/utils/Internet.php index 093b3b94f..3f3baf5c3 100644 --- a/src/pocketmine/utils/Internet.php +++ b/src/pocketmine/utils/Internet.php @@ -86,7 +86,7 @@ class Internet{ try{ list($ret, $headers, $httpCode) = self::simpleCurl($page, $timeout, $extraHeaders); return $ret; - }catch(\RuntimeException $ex){ + }catch(InternetException $ex){ $err = $ex->getMessage(); return false; } @@ -113,7 +113,7 @@ class Internet{ CURLOPT_POSTFIELDS => $args ]); return $ret; - }catch(\RuntimeException $ex){ + }catch(InternetException $ex){ $err = $ex->getMessage(); return false; } From 12d8d925c800ee9f981b722998ca6c2bc40de1c8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 4 Aug 2018 14:59:31 +0100 Subject: [PATCH 2/2] TimingsCommand: check for instances of InternetException only --- src/pocketmine/command/defaults/TimingsCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/command/defaults/TimingsCommand.php b/src/pocketmine/command/defaults/TimingsCommand.php index 8b2846e81..3f6e10806 100644 --- a/src/pocketmine/command/defaults/TimingsCommand.php +++ b/src/pocketmine/command/defaults/TimingsCommand.php @@ -30,6 +30,7 @@ use pocketmine\Player; use pocketmine\scheduler\BulkCurlTask; use pocketmine\Server; use pocketmine\timings\TimingsHandler; +use pocketmine\utils\InternetException; class TimingsCommand extends VanillaCommand{ @@ -131,7 +132,7 @@ class TimingsCommand extends VanillaCommand{ return; } $result = $this->getResult()[0]; - if($result instanceof \RuntimeException){ + if($result instanceof InternetException){ $server->getLogger()->logException($result); return; }