From f4c16ed0dbd1af79ed5fe69b87284f6453906c28 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Thu, 6 Aug 2020 20:47:39 +0200 Subject: [PATCH] eh cleanups (#1458) current exception sometimes buggy in nim --- beacon_chain/eth2_network.nim | 8 ++++---- beacon_chain/mainchain_monitor.nim | 2 +- beacon_chain/peer_pool.nim | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/beacon_chain/eth2_network.nim b/beacon_chain/eth2_network.nim index 038ec5ecd..e6f6b7d70 100644 --- a/beacon_chain/eth2_network.nim +++ b/beacon_chain/eth2_network.nim @@ -280,9 +280,9 @@ proc openStream(node: Eth2Node, let protocolId = protocolId & (if peer.lacksSnappy: "ssz" else: "ssz_snappy") try: result = await dial(node.switch, peer.info.peerId, peer.info.addrs, protocolId) - except CancelledError: - raise - except CatchableError: + except CancelledError as exc: + raise exc + except CatchableError as exc: # TODO: LibP2P should raise a more specific exception here if peer.lacksSnappy == false: peer.lacksSnappy = true @@ -290,7 +290,7 @@ proc openStream(node: Eth2Node, peer, protocolId return await openStream(node, peer, protocolId) else: - raise + raise exc proc init*(T: type Peer, network: Eth2Node, info: PeerInfo): Peer {.gcsafe.} diff --git a/beacon_chain/mainchain_monitor.nim b/beacon_chain/mainchain_monitor.nim index d56804346..10e4cbf4b 100644 --- a/beacon_chain/mainchain_monitor.nim +++ b/beacon_chain/mainchain_monitor.nim @@ -321,7 +321,7 @@ proc getBlockNumber(p: DataProviderRef, hash: BlockHash): Future[Eth1BlockNumber except CatchableError as exc: notice "Failed to get Eth1 block number from hash", hash = $hash, err = exc.msg - raise + raise exc template readJsonField(j: JsonNode, fieldName: string, diff --git a/beacon_chain/peer_pool.nim b/beacon_chain/peer_pool.nim index afaf19631..8c2791f59 100644 --- a/beacon_chain/peer_pool.nim +++ b/beacon_chain/peer_pool.nim @@ -94,12 +94,12 @@ proc waitForEvent[A, B](pool: PeerPool[A, B], eventType: EventType, if not(fut1.finished): fut1.cancel() outgoingEvent(eventType).clear() - except CancelledError: + except CancelledError as exc: if not(fut1.finished): fut1.cancel() if not(fut2.finished): fut2.cancel() - raise + raise exc elif PeerType.Incoming in filter: await incomingEvent(eventType).wait() incomingEvent(eventType).clear() @@ -497,13 +497,13 @@ proc acquire*[A, B](pool: PeerPool[A, B], doAssert(PeerFlags.Acquired notin item[].flags) item[].flags.incl(PeerFlags.Acquired) peers.add(item[].data) - except CancelledError: + except CancelledError as exc: # If we got cancelled, we need to return all the acquired peers back to # pool. for item in peers: pool.release(item) peers.setLen(0) - raise + raise exc result = peers proc acquireNoWait*[A, B](pool: PeerPool[A, B],