From fba2c96b6e092b54634c4ead4824512fc21552ac Mon Sep 17 00:00:00 2001 From: shimon Date: Sun, 3 Aug 2025 10:06:14 +0300 Subject: [PATCH 1/3] Add error handling for MongoDB connection failure in Client class --- src/Client.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 9f7ef2ee2d..9299cbddcd 100644 --- a/src/Client.php +++ b/src/Client.php @@ -118,8 +118,11 @@ class Client if ($this->client->isConnected()) { return $this; } + + if(!$this->client->connect($this->host, $this->port)){ + throw new \Exception("Failed to connect to MongoDB"); + } - $this->client->connect($this->host, $this->port); [$payload, $db] = $this->auth->start(); $res = $this->query($payload, $db); @@ -934,4 +937,4 @@ class Client $this->replicaSet = property_exists($result, 'setName'); return $this->replicaSet; } -} +} \ No newline at end of file From 3fd9db4ec2a86a5d4f1a8019b29913ed6eb2701c Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 4 Aug 2025 21:34:23 +1200 Subject: [PATCH 2/3] Update src/Client.php Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/Client.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Client.php b/src/Client.php index 9299cbddcd..c2e68eb203 100644 --- a/src/Client.php +++ b/src/Client.php @@ -118,10 +118,9 @@ class Client if ($this->client->isConnected()) { return $this; } - - if(!$this->client->connect($this->host, $this->port)){ - throw new \Exception("Failed to connect to MongoDB"); - } + if (!$this->client->connect($this->host, $this->port)) { + throw new Exception("Failed to connect to MongoDB at {$this->host}:{$this->port}"); + } [$payload, $db] = $this->auth->start(); From 0d641bdf251268d56b64f295fa047d5bfaa23c46 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 4 Aug 2025 21:37:40 +1200 Subject: [PATCH 3/3] Lint --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index c2e68eb203..d52e2b28b6 100644 --- a/src/Client.php +++ b/src/Client.php @@ -936,4 +936,4 @@ class Client $this->replicaSet = property_exists($result, 'setName'); return $this->replicaSet; } -} \ No newline at end of file +}