Replace errors with exceptions

This commit is contained in:
Stuckinaboot 2018-10-29 13:13:39 +01:00
parent 2544f8dff5
commit e93ced5f6a
4 changed files with 18 additions and 12 deletions

View File

@ -28,4 +28,5 @@ class PeerData(IPeerData):
def get_metadata(self, key):
if key in self.metadata:
return self.metadata[key], None
return None, "key not found"
else:
raise Exception("key not found")

View File

@ -41,7 +41,8 @@ class IPeerData(ABC):
"""
:param key: key in KV pair
:return: val for key, error (only defined if key not found)
:return: val for key
:raise Exception: key not found exception
"""
def get_metadata(self, key):
pass

View File

@ -32,8 +32,9 @@ class PeerStore(IPeerStore):
def get_protocols(self, peer_id):
if peer_id in self.peer_map:
return self.peer_map[peer_id].get_protocols(), None
return None, peer_id + " not found"
return self.peer_map[peer_id].get_protocols()
else:
raise Exception("peer ID not found")
def add_protocols(self, peer_id, protocols):
peer = self.__create_or_get_peer(peer_id)
@ -44,9 +45,10 @@ class PeerStore(IPeerStore):
def get(self, peer_id, key):
if peer_id in self.peer_map:
val, error = self.peer_map[peer_id].get_metadata(key)
return val, error
return None, peer_id + " not found"
val = self.peer_map[peer_id].get_metadata(key)
return val
else:
raise Exception("peer ID not found")
def put(self, peer_id, key, val):
# <<?>>
@ -64,8 +66,9 @@ class PeerStore(IPeerStore):
def addrs(self, peer_id):
if peer_id in self.peer_map:
return self.peer_map[peer_id].get_addrs(), None
return None, peer_id + " not found"
return self.peer_map[peer_id].get_addrs()
else:
raise Exception("peer ID not found")
def clear_addrs(self, peer_id):
# Only clear addresses if the peer is in peer map

View File

@ -20,7 +20,8 @@ class IPeerStore(ABC, IAddrBook, IPeerMetadata):
def get_protocols(self, peer_id):
"""
:param peer_id: peer ID to get protocols for
:return: protocols (as strings), error
:return: protocols (as strings)
:raise Exception: peer ID not found exception
"""
pass
@ -29,7 +30,7 @@ class IPeerStore(ABC, IAddrBook, IPeerMetadata):
"""
:param peer_id: peer ID to add protocols for
:param protocols: protocols to add
:return: error
:raise Exception: peer ID not found exception
"""
pass
@ -38,7 +39,7 @@ class IPeerStore(ABC, IAddrBook, IPeerMetadata):
"""
:param peer_id: peer ID to set protocols for
:param protocols: protocols to set
:return: error
:raise Exception: peer ID not found exception
"""
pass