diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2015-02-06 19:33:06 -0800 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2015-02-06 19:33:06 -0800 |
commit | f99e1d8775be20c471c39f8d7a91126b8419381d (patch) | |
tree | cd19913be70ba5a3a51e15738c31252e1ff9fa7a /paramiko/ssh_exception.py | |
parent | b42b5338de868c3a5343dd03a8ee3f8a968d2f65 (diff) | |
download | paramiko-f99e1d8775be20c471c39f8d7a91126b8419381d.tar.gz |
Raise usefully ambiguous error when every connect attempt fails.
Re #22
Diffstat (limited to 'paramiko/ssh_exception.py')
-rw-r--r-- | paramiko/ssh_exception.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/paramiko/ssh_exception.py b/paramiko/ssh_exception.py index b99e42b3..7e6f2568 100644 --- a/paramiko/ssh_exception.py +++ b/paramiko/ssh_exception.py @@ -16,6 +16,8 @@ # along with Paramiko; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +import socket + class SSHException (Exception): """ @@ -129,3 +131,31 @@ class ProxyCommandFailure (SSHException): self.error = error # for unpickling self.args = (command, error, ) + + +class ConnectionError(socket.error): + """ + High-level socket error wrapping 1+ actual socket.error objects. + + To see the wrapped exception objects, access the ``errors`` attribute. + ``errors`` is a dict whose keys are address tuples (e.g. ``('127.0.0.1', + 22)``) and whose values are the exception encountered trying to connect to + that address. + + It is implied/assumed that all the errors given to a single instance of + this class are from connecting to the same hostname + port (and thus that + the differences are in the resolution of the hostname - e.g. IPv4 vs v6). + """ + def __init__(self, errors): + """ + :param dict errors: + The errors dict to store, as described by class docstring. + """ + addrs = errors.keys() + body = ', '.join([x[0] for x in addrs[:-1]]) + tail = addrs[-1][0] + msg = "Unable to connect to port {0} at {1} or {2}" + super(ConnectionError, self).__init__( + msg.format(addrs[0][1], body, tail) + ) + self.errors = errors |