eh cleanups (#1458)

current exception sometimes buggy in nim
This commit is contained in:
Jacek Sieka 2020-08-06 20:47:39 +02:00 committed by GitHub
parent 8890d014be
commit f4c16ed0db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View File

@ -280,9 +280,9 @@ proc openStream(node: Eth2Node,
let protocolId = protocolId & (if peer.lacksSnappy: "ssz" else: "ssz_snappy") let protocolId = protocolId & (if peer.lacksSnappy: "ssz" else: "ssz_snappy")
try: try:
result = await dial(node.switch, peer.info.peerId, peer.info.addrs, protocolId) result = await dial(node.switch, peer.info.peerId, peer.info.addrs, protocolId)
except CancelledError: except CancelledError as exc:
raise raise exc
except CatchableError: except CatchableError as exc:
# TODO: LibP2P should raise a more specific exception here # TODO: LibP2P should raise a more specific exception here
if peer.lacksSnappy == false: if peer.lacksSnappy == false:
peer.lacksSnappy = true peer.lacksSnappy = true
@ -290,7 +290,7 @@ proc openStream(node: Eth2Node,
peer, protocolId peer, protocolId
return await openStream(node, peer, protocolId) return await openStream(node, peer, protocolId)
else: else:
raise raise exc
proc init*(T: type Peer, network: Eth2Node, info: PeerInfo): Peer {.gcsafe.} proc init*(T: type Peer, network: Eth2Node, info: PeerInfo): Peer {.gcsafe.}

View File

@ -321,7 +321,7 @@ proc getBlockNumber(p: DataProviderRef, hash: BlockHash): Future[Eth1BlockNumber
except CatchableError as exc: except CatchableError as exc:
notice "Failed to get Eth1 block number from hash", notice "Failed to get Eth1 block number from hash",
hash = $hash, err = exc.msg hash = $hash, err = exc.msg
raise raise exc
template readJsonField(j: JsonNode, template readJsonField(j: JsonNode,
fieldName: string, fieldName: string,

View File

@ -94,12 +94,12 @@ proc waitForEvent[A, B](pool: PeerPool[A, B], eventType: EventType,
if not(fut1.finished): if not(fut1.finished):
fut1.cancel() fut1.cancel()
outgoingEvent(eventType).clear() outgoingEvent(eventType).clear()
except CancelledError: except CancelledError as exc:
if not(fut1.finished): if not(fut1.finished):
fut1.cancel() fut1.cancel()
if not(fut2.finished): if not(fut2.finished):
fut2.cancel() fut2.cancel()
raise raise exc
elif PeerType.Incoming in filter: elif PeerType.Incoming in filter:
await incomingEvent(eventType).wait() await incomingEvent(eventType).wait()
incomingEvent(eventType).clear() incomingEvent(eventType).clear()
@ -497,13 +497,13 @@ proc acquire*[A, B](pool: PeerPool[A, B],
doAssert(PeerFlags.Acquired notin item[].flags) doAssert(PeerFlags.Acquired notin item[].flags)
item[].flags.incl(PeerFlags.Acquired) item[].flags.incl(PeerFlags.Acquired)
peers.add(item[].data) peers.add(item[].data)
except CancelledError: except CancelledError as exc:
# If we got cancelled, we need to return all the acquired peers back to # If we got cancelled, we need to return all the acquired peers back to
# pool. # pool.
for item in peers: for item in peers:
pool.release(item) pool.release(item)
peers.setLen(0) peers.setLen(0)
raise raise exc
result = peers result = peers
proc acquireNoWait*[A, B](pool: PeerPool[A, B], proc acquireNoWait*[A, B](pool: PeerPool[A, B],