summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNorman J. Harman Jr <njharman@gmail.com>2017-09-11 17:50:33 -0500
committerJon Parise <jon@pinterest.com>2017-09-11 15:50:33 -0700
commit0745c9ffbb511563a8dad28fdf4d92c149d1de8c (patch)
tree77ee9d89156373908a749251c6856f728be47d6a
parentfe241ceafc317f40b7a03d514279397c3c7e731f (diff)
downloadpymemcache-0745c9ffbb511563a8dad28fdf4d92c149d1de8c.tar.gz
Don't Raise Generic Exception (#164)
Libraries should raise library specific exceptions. Such as MemcacheError. This enables users to easily catch exceptions generated by library separate from other exceptions. Raising "Exception" forces catching Exception and potentially masks all sorts of issues.
-rw-r--r--pymemcache/client/hash.py3
-rw-r--r--pymemcache/test/test_client_hash.py4
2 files changed, 4 insertions, 3 deletions
diff --git a/pymemcache/client/hash.py b/pymemcache/client/hash.py
index 6c9c298..7766aaa 100644
--- a/pymemcache/client/hash.py
+++ b/pymemcache/client/hash.py
@@ -4,6 +4,7 @@ import logging
from pymemcache.client.base import Client, PooledClient, _check_key
from pymemcache.client.rendezvous import RendezvousHash
+from pymemcache.exceptions import MemcacheError
logger = logging.getLogger(__name__)
@@ -132,7 +133,7 @@ class HashClient(object):
if server is None:
if self.ignore_exc is True:
return
- raise Exception('All servers seem to be down right now')
+ raise MemcacheError('All servers seem to be down right now')
client = self.clients[server]
return client
diff --git a/pymemcache/test/test_client_hash.py b/pymemcache/test/test_client_hash.py
index 1601be6..e8437d3 100644
--- a/pymemcache/test/test_client_hash.py
+++ b/pymemcache/test/test_client_hash.py
@@ -1,6 +1,6 @@
from pymemcache.client.hash import HashClient
from pymemcache.client.base import Client, PooledClient
-from pymemcache.exceptions import MemcacheUnknownError
+from pymemcache.exceptions import MemcacheError, MemcacheUnknownError
from pymemcache import pool
from .test_client import ClientTestMixin, MockSocket
@@ -162,7 +162,7 @@ class TestHashClient(ClientTestMixin, unittest.TestCase):
timeout=1, connect_timeout=1
)
- with pytest.raises(Exception) as e:
+ with pytest.raises(MemcacheError) as e:
client._get_client('foo')
assert str(e.value) == 'All servers seem to be down right now'