From 99568190f6e13a381830f397a492896045610fff Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Wed, 7 Aug 2019 21:27:34 +0100 Subject: [PATCH] Throw exception if there is a connection error --- src/SSHConnection.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/SSHConnection.php b/src/SSHConnection.php index 67618fb..9b5ec66 100644 --- a/src/SSHConnection.php +++ b/src/SSHConnection.php @@ -68,6 +68,10 @@ public function connect(): self $this->resource = ssh2_connect($this->hostname, $this->port); + if (!$this->resource) { + throw new RuntimeException('Error connecting to server.'); + } + if ($this->publicKeyPath || $this->privateKeyPath) { $authenticated = ssh2_auth_pubkey_file($this->resource, $this->username, $this->publicKeyPath, $this->privateKeyPath); if (!$authenticated) {