Update exception type

This commit is contained in:
Stuckinaboot 2018-10-30 00:03:19 +01:00
parent 95d3847d5a
commit 869d2db847
5 changed files with 20 additions and 10 deletions

View File

@ -27,6 +27,10 @@ class PeerData(IPeerData):
def get_metadata(self, key):
if key in self.metadata:
return self.metadata[key], None
return self.metadata[key]
else:
raise Exception("key not found")
raise PeerDataError("key not found")
class PeerDataError(KeyError):
"""Raised when a key is not found in peer metadata"""
pass

View File

@ -35,6 +35,7 @@ class IPeerData(ABC):
"""
:param key: key in KV pair
:param val: val to associate with key
:raise Exception: unsuccesful put
"""
def put_metadata(self, key, val):
pass
@ -42,7 +43,7 @@ class IPeerData(ABC):
"""
:param key: key in KV pair
:return: val for key
:raise Exception: key not found exception
:raise Exception: key not found
"""
def get_metadata(self, key):
pass

View File

@ -10,7 +10,8 @@ class IPeerMetadata(ABC):
"""
:param peer_id: peer ID to lookup key for
:param key: key to look up
:return: value at key for given peer, error
:return: value at key for given peer
:raise Exception: peer ID not found
"""
pass
@ -20,7 +21,7 @@ class IPeerMetadata(ABC):
:param peer_id: peer ID to lookup key for
:param key: key to associate with peer
:param val: value to associated with key
:return: error
:raise Exception: unsuccessful put
"""
pass

View File

@ -32,7 +32,7 @@ class PeerStore(IPeerStore):
if peer_id in self.peer_map:
return self.peer_map[peer_id].get_protocols()
else:
raise Exception("peer ID not found")
raise PeerStoreError("peer ID not found")
def add_protocols(self, peer_id, protocols):
peer = self.__create_or_get_peer(peer_id)
@ -46,7 +46,7 @@ class PeerStore(IPeerStore):
val = self.peer_map[peer_id].get_metadata(key)
return val
else:
raise Exception("peer ID not found")
raise PeerStoreError("peer ID not found")
def put(self, peer_id, key, val):
# <<?>>
@ -66,7 +66,7 @@ class PeerStore(IPeerStore):
if peer_id in self.peer_map:
return self.peer_map[peer_id].get_addrs()
else:
raise Exception("peer ID not found")
raise PeerStoreError("peer ID not found")
def clear_addrs(self, peer_id):
# Only clear addresses if the peer is in peer map
@ -81,3 +81,7 @@ class PeerStore(IPeerStore):
if len(self.peer_map[key].get_addrs()) >= 1:
output.append(key)
return output
class PeerStoreError(KeyError):
"""Raised when peer ID is not found in peer store"""
pass

View File

@ -30,7 +30,7 @@ class IPeerStore(ABC, IAddrBook, IPeerMetadata):
"""
:param peer_id: peer ID to add protocols for
:param protocols: protocols to add
:raise Exception: peer ID not found exception
:raise Exception: peer ID not found
"""
pass
@ -39,7 +39,7 @@ class IPeerStore(ABC, IAddrBook, IPeerMetadata):
"""
:param peer_id: peer ID to set protocols for
:param protocols: protocols to set
:raise Exception: peer ID not found exception
:raise Exception: peer ID not found
"""
pass