From 1a03156040f97224fd0008899e2212be918cc96e Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 4 Aug 2025 10:59:28 +0100 Subject: [PATCH 1/2] Use exception chaining to provide the decoding error information --- src/Communication/Connection.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Communication/Connection.php b/src/Communication/Connection.php index de97c87..5ed6d20 100644 --- a/src/Communication/Connection.php +++ b/src/Communication/Connection.php @@ -372,14 +372,11 @@ public function processAllEvents(): void */ private function dispatchMessage(string $message, ?Session $session = null) { - // responses come as json string - $response = \json_decode($message, true); - - // if json not valid throw exception - $jsonError = \json_last_error(); - if (\JSON_ERROR_NONE !== $jsonError) { + try { + $response = \json_decode($message, true, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { if ($this->isStrict()) { - throw new CannotReadResponse(\sprintf('Response from chrome remote interface is not a valid json response. JSON error: %s', $jsonError)); + throw new CannotReadResponse('Response from chrome remote interface is not a valid JSON response', 0, $e); } return false; From 46e2b6f1dc37be54da8aaa65dfff8a81a872d2fc Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 4 Aug 2025 09:59:41 +0000 Subject: [PATCH 2/2] Apply fixes from StyleCI --- src/Communication/Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Communication/Connection.php b/src/Communication/Connection.php index 5ed6d20..d307e8e 100644 --- a/src/Communication/Connection.php +++ b/src/Communication/Connection.php @@ -373,7 +373,7 @@ public function processAllEvents(): void private function dispatchMessage(string $message, ?Session $session = null) { try { - $response = \json_decode($message, true, 512, JSON_THROW_ON_ERROR); + $response = \json_decode($message, true, 512, \JSON_THROW_ON_ERROR); } catch (\JsonException $e) { if ($this->isStrict()) { throw new CannotReadResponse('Response from chrome remote interface is not a valid JSON response', 0, $e);