diff options
author | Andy McCurdy <andy@andymccurdy.com> | 2011-06-07 02:48:29 -0700 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2011-06-07 02:48:29 -0700 |
commit | 146db39bc8997af03d3661e00b61bd756529a4ca (patch) | |
tree | b0d9d77c1f50976fddf75f77389f55d198ffea9f /redis/connection.py | |
parent | 88a3a3caef3d1752e3bef258d0ea3e4d29866450 (diff) | |
download | redis-py-146db39bc8997af03d3661e00b61bd756529a4ca.tar.gz |
fix UnixDomainSocketConnection to report error messages based on it's attributes rather than the TCP socket attributes. fixes #140
Diffstat (limited to 'redis/connection.py')
-rw-r--r-- | redis/connection.py | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/redis/connection.py b/redis/connection.py index 128c359..b0383f5 100644 --- a/redis/connection.py +++ b/redis/connection.py @@ -124,15 +124,7 @@ class Connection(object): try: sock = self._connect() except socket.error, e: - # args for socket.error can either be (errno, "message") - # or just "message" - if len(e.args) == 1: - error_message = "Error connecting to %s:%s. %s." % \ - (self.host, self.port, e.args[0]) - else: - error_message = "Error %s connecting %s:%s. %s." % \ - (e.args[0], self.host, self.port, e.args[1]) - raise ConnectionError(error_message) + raise ConnectionError(self._error_mesage(e)) self._sock = sock self.on_connect() @@ -144,6 +136,17 @@ class Connection(object): sock.connect((self.host, self.port)) return sock + def _error_message(self, exception): + # args for socket.error can either be (errno, "message") + # or just "message" + if len(exception.args) == 1: + return "Error connecting to %s:%s. %s." % \ + (self.host, self.port, exception.args[0]) + else: + return "Error %s connecting %s:%s. %s." % \ + (exception.args[0], self.host, self.port, exception.args[1]) + + def on_connect(self): "Initialize the connection, authenticate and select a database" self._parser.on_connect(self) @@ -241,6 +244,17 @@ class UnixDomainSocketConnection(Connection): sock.connect(self.path) return sock + def _error_message(self, exception): + # args for socket.error can either be (errno, "message") + # or just "message" + if len(exception.args) == 1: + return "Error connecting to unix socket: %s. %s." % \ + (self.path, exception.args[0]) + else: + return "Error %s connecting to unix socket: %s. %s." % \ + (exception.args[0], self.path, exception.args[1]) + + # TODO: add ability to block waiting on a connection to be released class ConnectionPool(object): "Generic connection pool" |