Add raises annotations to make exception tracking work (#336)

See https://github.com/status-im/nim-chronos/pull/166
This commit is contained in:
Kim De Mey 2021-03-24 12:52:09 +01:00 committed by GitHub
parent 16802c0e52
commit 0be863d2de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 11 deletions

View File

@ -139,13 +139,14 @@ type
MessageHandlerDecorator* = proc(msgId: int, n: NimNode): NimNode
ThunkProc* = proc(x: Peer, msgId: int, data: Rlp): Future[void] {.gcsafe.}
MessageContentPrinter* = proc(msg: pointer): string {.gcsafe.}
RequestResolver* = proc(msg: pointer, future: FutureBase) {.gcsafe.}
RequestResolver* = proc(msg: pointer, future: FutureBase)
{.gcsafe, raises:[Defect].}
NextMsgResolver* = proc(msgData: Rlp, future: FutureBase) {.gcsafe.}
PeerStateInitializer* = proc(peer: Peer): RootRef {.gcsafe.}
NetworkStateInitializer* = proc(network: EthereumNode): RootRef {.gcsafe.}
HandshakeStep* = proc(peer: Peer): Future[void] {.gcsafe.}
DisconnectionHandler* = proc(peer: Peer,
reason: DisconnectionReason): Future[void] {.gcsafe.}
DisconnectionHandler* = proc(peer: Peer, reason: DisconnectionReason):
Future[void] {.gcsafe.}
ConnectionState* = enum
None,

View File

@ -60,7 +60,8 @@ chronicles.formatIt(Peer): $(it.remote)
include p2p_backends_helpers
proc requestResolver[MsgType](msg: pointer, future: FutureBase) {.gcsafe.} =
proc requestResolver[MsgType](msg: pointer, future: FutureBase)
{.gcsafe, raises:[Defect].} =
var f = Future[Option[MsgType]](future)
if not f.finished:
if msg != nil:
@ -72,10 +73,13 @@ proc requestResolver[MsgType](msg: pointer, future: FutureBase) {.gcsafe.} =
# here. The only reasonable explanation is that the request should
# have timed out.
if msg != nil:
if f.read.isSome:
doAssert false, "trying to resolve a request twice"
else:
doAssert false, "trying to resolve a timed out request with a value"
try:
if f.read.isSome:
doAssert false, "trying to resolve a request twice"
else:
doAssert false, "trying to resolve a timed out request with a value"
except CatchableError as e:
debug "Exception in requestResolver()", exc = e.name, err = e.msg
else:
try:
if not f.read.isSome:
@ -88,9 +92,8 @@ proc requestResolver[MsgType](msg: pointer, future: FutureBase) {.gcsafe.} =
trace "TransportOsError during request", err = e.msg
except TransportError:
trace "Transport got closed during request"
except Exception as e:
except CatchableError as e:
debug "Exception in requestResolver()", exc = e.name, err = e.msg
raise e
proc linkSendFailureToReqFuture[S, R](sendFut: Future[S], resFut: Future[R]) =
sendFut.addCallback() do (arg: pointer):
@ -360,7 +363,8 @@ proc registerRequest(peer: Peer,
doAssert(not peer.dispatcher.isNil)
let requestResolver = peer.dispatcher.messages[responseMsgId].requestResolver
proc timeoutExpired(udata: pointer) = requestResolver(nil, responseFuture)
proc timeoutExpired(udata: pointer) {.gcsafe, raises:[Defect].} =
requestResolver(nil, responseFuture)
addTimer(timeoutAt, timeoutExpired, nil)