apply PR feedback (remote len == 0 block, remove redundant fixme comment + docstring line)

change wording of final SwarmException to include possible case of no addresses in returned address set

add `from error` in except clause
This commit is contained in:
Jonathan de Jong 2019-12-17 20:20:09 +01:00
parent 3cbe24caab
commit 6b75901243

View File

@ -88,11 +88,8 @@ class Swarm(INetwork):
try: try:
# Get peer info from peer store # Get peer info from peer store
addrs = self.peerstore.addrs(peer_id) addrs = self.peerstore.addrs(peer_id)
except PeerStoreError: except PeerStoreError as error:
raise SwarmException(f"No known addresses to peer {peer_id}") raise SwarmException(f"No known addresses to peer {peer_id}") from error
if len(addrs) == 0:
raise SwarmException(f"No known addresses to peer {peer_id}")
exceptions: List[SwarmException] = [] exceptions: List[SwarmException] = []
@ -112,12 +109,16 @@ class Swarm(INetwork):
# Tried all addresses, raising exception. # Tried all addresses, raising exception.
if len(exceptions) > 0: if len(exceptions) > 0:
raise SwarmException( raise SwarmException(
"unable to connect to %s, all addresses failed to dial (with exceptions)", "unable to connect to %s, no addresses established a successful connection "
"(with exceptions)",
peer_id, peer_id,
) from MultiError(exceptions) ) from MultiError(exceptions)
else: else:
raise SwarmException( raise SwarmException(
"unable to connect to %s, all addresses failed to dial", peer_id "unable to connect to %s, no addresses established a successful connection "
"(tried %d addresses)",
peer_id,
len(addrs),
) )
async def dial_addr(self, addr: Multiaddr, peer_id: ID) -> INetConn: async def dial_addr(self, addr: Multiaddr, peer_id: ID) -> INetConn:
@ -173,7 +174,6 @@ class Swarm(INetwork):
async def new_stream(self, peer_id: ID) -> INetStream: async def new_stream(self, peer_id: ID) -> INetStream:
""" """
:param peer_id: peer_id of destination :param peer_id: peer_id of destination
:param protocol_id: protocol id fixme: protocol_id not in parameters
:raises SwarmException: raised when an error occurs :raises SwarmException: raised when an error occurs
:return: net stream instance :return: net stream instance
""" """