diff options
author | Greg Ward <greg@gerg.ca> | 2016-01-21 09:10:12 -0500 |
---|---|---|
committer | Greg Ward <greg@gerg.ca> | 2016-06-12 19:28:43 -0400 |
commit | 86ec8d0458e39c795321348f189457c52ebcceca (patch) | |
tree | 6280543cc5d1fd4b9fdb24528183f76b06aa92cb /redis/client.py | |
parent | 3bdf81ab41464d8e918080234912fc8fd86629af (diff) | |
download | redis-py-86ec8d0458e39c795321348f189457c52ebcceca.tar.gz |
pubsub: improve error reporting if caller forgets to subscribe
This is an easy mistake to make -- at least, I keep making it. It
formerly resulted in a confusing crash, "AttributeError: 'NoneType'
object has no attribute 'can_read'", from parse_response(). I have had
to dig into the redis-py source code more than once to figure out what
went wrong.
With this patch, it still crashes, but with a clearer error that
clarifies what the calling code forgot to do.
Fixes issue #716.
Diffstat (limited to 'redis/client.py')
-rwxr-xr-x | redis/client.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py index d6bd5c3..d84c8b3 100755 --- a/redis/client.py +++ b/redis/client.py @@ -2226,6 +2226,10 @@ class PubSub(object): def parse_response(self, block=True, timeout=0): "Parse the response from a publish/subscribe command" connection = self.connection + if connection is None: + raise RuntimeError( + 'pubsub connection not set: ' + 'did you forget to call subscribe() or psubscribe()?') if not block and not connection.can_read(timeout=timeout): return None return self._execute(connection, connection.read_response) |