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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user