From 70911186633bb4ddfa4dec7940419bef6ff7f4f8 Mon Sep 17 00:00:00 2001 From: Fuxino Date: Thu, 8 Oct 2026 20:14:39 +0200 Subject: [PATCH] Handle SSH connection errors instead of crashing An unknown hostname, a refused connection or an unreachable server raise OSError (socket.gaierror, NoValidConnectionsError), which paramiko.SSHException doesn't cover, so the program crashed with a traceback. Log the error and exit with code 5 instead. --- simple_backup/simple_backup.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/simple_backup/simple_backup.py b/simple_backup/simple_backup.py index 18f8893..15fec5d 100755 --- a/simple_backup/simple_backup.py +++ b/simple_backup/simple_backup.py @@ -177,7 +177,14 @@ class Backup: self._remote = True if self._remote: - self._ssh = self._ssh_connect(homedir) + try: + self._ssh = self._ssh_connect(homedir) + except OSError as e: + # Unknown hostname, connection refused, unreachable host or timeout + logger.critical('Can\'t connect to the server %s', self.ssh_host) + logger.critical(e) + + return 5 if self._ssh is None: return 5