Replace getCurrentException and getCurrentExceptionMsg

This commit is contained in:
kdeme 2019-12-02 16:31:10 +01:00 committed by zah
parent a54fdc8073
commit 4976bd9fb9
11 changed files with 46 additions and 57 deletions

View File

@ -71,8 +71,8 @@ proc getExternalIP*(natStrategy: NatStrategy, quiet = false): Option[IpAddress]
externalIP = parseIpAddress(ires.value) externalIP = parseIpAddress(ires.value)
strategy = NatUpnp strategy = NatUpnp
return some(externalIP) return some(externalIP)
except: except ValueError as e:
error "parseIpAddress() exception", err = getCurrentExceptionMsg() error "parseIpAddress() exception", err = e.msg
return return
if natStrategy == NatAny or natStrategy == NatPmp: if natStrategy == NatAny or natStrategy == NatPmp:
@ -89,8 +89,8 @@ proc getExternalIP*(natStrategy: NatStrategy, quiet = false): Option[IpAddress]
externalIP = parseIpAddress($(nires.value)) externalIP = parseIpAddress($(nires.value))
strategy = NatPmp strategy = NatPmp
return some(externalIP) return some(externalIP)
except: except ValueError as e:
error "parseIpAddress() exception", err = getCurrentExceptionMsg() error "parseIpAddress() exception", err = e.msg
return return
proc doPortMapping(tcpPort, udpPort: Port, description: string): Option[(Port, Port)] {.gcsafe.} = proc doPortMapping(tcpPort, udpPort: Port, description: string): Option[(Port, Port)] {.gcsafe.} =

View File

@ -198,10 +198,8 @@ proc obtainBlocksFromPeer(syncCtx: SyncContext, peer: Peer) {.async.} =
syncCtx.endBlockNumber = bestBlockNumber syncCtx.endBlockNumber = bestBlockNumber
except TransportError: except TransportError:
debug "Transport got closed during obtainBlocksFromPeer" debug "Transport got closed during obtainBlocksFromPeer"
except CatchableError: except CatchableError as e:
debug "Exception in getBestBlockNumber()", debug "Exception in getBestBlockNumber()", exc = e.name, err = e.msg
exc = getCurrentException().name,
err = getCurrentExceptionMsg()
# no need to exit here, because the context might still have blocks to fetch # no need to exit here, because the context might still have blocks to fetch
# from this peer # from this peer
@ -252,13 +250,11 @@ proc obtainBlocksFromPeer(syncCtx: SyncContext, peer: Peer) {.async.} =
warn "Bodies len != headers.len", bodies = bodies.len, headers = workItem.headers.len warn "Bodies len != headers.len", bodies = bodies.len, headers = workItem.headers.len
except TransportError: except TransportError:
debug "Transport got closed during obtainBlocksFromPeer" debug "Transport got closed during obtainBlocksFromPeer"
except CatchableError: except CatchableError as e:
# the success case sets `dataReceived`, so we can just fall back to the # the success case sets `dataReceived`, so we can just fall back to the
# failure path below. If we signal time-outs with exceptions such # failure path below. If we signal time-outs with exceptions such
# failures will be easier to handle. # failures will be easier to handle.
debug "Exception in obtainBlocksFromPeer()", debug "Exception in obtainBlocksFromPeer()", exc = e.name, err = e.msg
exc = getCurrentException().name,
err = getCurrentExceptionMsg()
var giveUpOnPeer = false var giveUpOnPeer = false
@ -365,10 +361,8 @@ proc onPeerConnected(ctx: SyncContext, peer: Peer) =
error "startSyncWithPeer failed", msg = f.readError.msg, peer error "startSyncWithPeer failed", msg = f.readError.msg, peer
except TransportError: except TransportError:
debug "Transport got closed during startSyncWithPeer" debug "Transport got closed during startSyncWithPeer"
except CatchableError: except CatchableError as e:
debug "Exception in startSyncWithPeer()", debug "Exception in startSyncWithPeer()", exc = e.name, err = e.msg
exc = getCurrentException().name,
err = getCurrentExceptionMsg()
proc onPeerDisconnected(ctx: SyncContext, p: Peer) = proc onPeerDisconnected(ctx: SyncContext, p: Peer) =

View File

@ -263,10 +263,12 @@ proc processClient(transp: DatagramTransport,
var buf = transp.getMessage() var buf = transp.getMessage()
let a = Address(ip: raddr.address, udpPort: raddr.port, tcpPort: raddr.port) let a = Address(ip: raddr.address, udpPort: raddr.port, tcpPort: raddr.port)
proto.receive(a, buf) proto.receive(a, buf)
except RlpError, DiscProtocolError: except RlpError as e:
debug "Receive failed", err = getCurrentExceptionMsg() debug "Receive failed", exc = e.name, err = e.msg
except: except DiscProtocolError as e:
debug "Receive failed", err = getCurrentExceptionMsg() debug "Receive failed", exc = e.name, err = e.msg
except Exception as e:
debug "Receive failed", exc = e.name, err = e.msg
raise raise
proc open*(d: DiscoveryProtocol) = proc open*(d: DiscoveryProtocol) =

View File

@ -66,15 +66,13 @@ proc requestResolver[MsgType](msg: pointer, future: FutureBase) {.gcsafe.} =
# This can except when the future still completes with an error. # This can except when the future still completes with an error.
# E.g. the `sendMsg` fails because of an already closed transport or a # E.g. the `sendMsg` fails because of an already closed transport or a
# broken pipe # broken pipe
except TransportOsError: except TransportOsError as e:
# E.g. broken pipe # E.g. broken pipe
trace "TransportOsError during request", err = getCurrentExceptionMsg() trace "TransportOsError during request", err = e.msg
except TransportError: except TransportError:
trace "Transport got closed during request" trace "Transport got closed during request"
except: except Exception as e:
debug "Exception in requestResolver()", debug "Exception in requestResolver()", exc = e.name, err = e.msg
exc = getCurrentException().name,
err = getCurrentExceptionMsg()
raise raise
proc linkSendFailureToReqFuture[S, R](sendFut: Future[S], resFut: Future[R]) = proc linkSendFailureToReqFuture[S, R](sendFut: Future[S], resFut: Future[R]) =

View File

@ -173,8 +173,7 @@ proc run(p: PeerPool) {.async.} =
# Most unexpected errors should be transient, so we log and restart from # Most unexpected errors should be transient, so we log and restart from
# scratch. # scratch.
error "Unexpected PeerPool error, restarting", error "Unexpected PeerPool error, restarting",
err = getCurrentExceptionMsg(), err = e.msg, stackTrace = e.getStackTrace()
stackTrace = e.getStackTrace()
dropConnections = true dropConnections = true
if dropConnections: if dropConnections:

View File

@ -443,11 +443,11 @@ proc checkedRlpRead(peer: Peer, r: var Rlp, MsgType: type): auto {.inline.} =
else: else:
try: try:
return r.read(MsgType) return r.read(MsgType)
except: except Exception as e:
debug "Failed rlp.read", debug "Failed rlp.read",
peer = peer, peer = peer,
dataType = MsgType.name, dataType = MsgType.name,
exception = getCurrentExceptionMsg() exception = e.msg
# rlpData = r.inspect # rlpData = r.inspect
raise raise
@ -533,10 +533,9 @@ proc dispatchMessages*(peer: Peer) {.async.} =
msg = peer.getMsgName(msgId) msg = peer.getMsgName(msgId)
await peer.disconnect(BreachOfProtocol, true) await peer.disconnect(BreachOfProtocol, true)
return return
except CatchableError: except CatchableError as e:
warn "Error while handling RLPx message", peer, warn "Error while handling RLPx message", peer,
msg = peer.getMsgName(msgId), msg = peer.getMsgName(msgId), err = e.msg
err = getCurrentExceptionMsg()
# TODO: Hmm, this can be safely moved into the message handler thunk. # TODO: Hmm, this can be safely moved into the message handler thunk.
# The documentation will need to be updated, explaning the fact that # The documentation will need to be updated, explaning the fact that
@ -546,12 +545,12 @@ proc dispatchMessages*(peer: Peer) {.async.} =
let msgInfo = peer.dispatcher.messages[msgId] let msgInfo = peer.dispatcher.messages[msgId]
try: try:
(msgInfo.nextMsgResolver)(msgData, peer.awaitedMessages[msgId]) (msgInfo.nextMsgResolver)(msgData, peer.awaitedMessages[msgId])
except: except CatchableError as e:
# TODO: Handling errors here must be investigated more carefully. # TODO: Handling errors here must be investigated more carefully.
# They also are supposed to be handled at the call-site where # They also are supposed to be handled at the call-site where
# `nextMsg` is used. # `nextMsg` is used.
debug "nextMsg resolver failed, ending dispatchMessages loop", peer, debug "nextMsg resolver failed, ending dispatchMessages loop", peer,
err = getCurrentExceptionMsg() err = e.msg
await peer.disconnect(BreachOfProtocol, true) await peer.disconnect(BreachOfProtocol, true)
return return
peer.awaitedMessages[msgId] = nil peer.awaitedMessages[msgId] = nil
@ -1044,12 +1043,11 @@ proc rlpxConnect*(node: EthereumNode, remote: Node): Future[Peer] {.async.} =
# Some peers report capabilities with names longer than 3 chars. We ignore # Some peers report capabilities with names longer than 3 chars. We ignore
# those for now. Maybe we should allow this though. # those for now. Maybe we should allow this though.
debug "Rlp error in rlpxConnect" debug "Rlp error in rlpxConnect"
except TransportOsError: except TransportOsError as e:
trace "TransportOsError", err = getCurrentExceptionMsg() trace "TransportOsError", err = e.msg
except CatchableError: except CatchableError as e:
error "Unexpected exception in rlpxConnect", remote, error "Unexpected exception in rlpxConnect", remote, exc = e.name,
exc = getCurrentException().name, err = e.msg
err = getCurrentExceptionMsg()
if not ok: if not ok:
if not isNil(result.transport): if not isNil(result.transport):
@ -1152,12 +1150,10 @@ proc rlpxAccept*(node: EthereumNode,
# Some peers report capabilities with names longer than 3 chars. We ignore # Some peers report capabilities with names longer than 3 chars. We ignore
# those for now. Maybe we should allow this though. # those for now. Maybe we should allow this though.
debug "Rlp error in rlpxAccept" debug "Rlp error in rlpxAccept"
except TransportOsError: except TransportOsError as e:
trace "TransportOsError", err = getCurrentExceptionMsg() trace "TransportOsError", err = e.msg
except CatchableError: except CatchableError as e:
error "Unexpected exception in rlpxAccept", error "Unexpected exception in rlpxAccept", exc = e.name, err = e.msg
exc = getCurrentException().name,
err = getCurrentExceptionMsg()
if not ok: if not ok:
if not isNil(result.transport): if not isNil(result.transport):

View File

@ -118,9 +118,8 @@ proc loadMessageStats*(network: LesNetwork,
return true return true
except RlpError: except RlpError as e:
error "Error while loading LES message stats", error "Error while loading LES message stats", err = e.msg
err = getCurrentExceptionMsg()
newSeq(network.messageStats, les.messages[^1].id + 1) newSeq(network.messageStats, les.messages[^1].id + 1)
return false return false

View File

@ -30,5 +30,5 @@ test:
targetNode.receive(address, msg) targetNode.receive(address, msg)
# These errors are also catched in `processClient` in discovery.nim # These errors are also catched in `processClient` in discovery.nim
# TODO: move them a layer down in discovery so we can do a cleaner test there? # TODO: move them a layer down in discovery so we can do a cleaner test there?
except RlpError, DiscProtocolError: except RlpError, DiscProtocolError as e:
debug "Receive failed", err = getCurrentExceptionMsg() debug "Receive failed", err = e.msg

View File

@ -7,7 +7,8 @@ template fuzz(body) =
try: try:
body body
except Exception as e: except Exception as e:
error "Fuzzer input created exception", exception=e.name, trace=e.repr, msg=e.msg error "Fuzzer input created exception", exception=e.name, trace=e.repr,
msg=e.msg
discard kill(getpid(), SIGSEGV) discard kill(getpid(), SIGSEGV)
else: else:
body body

View File

@ -32,8 +32,8 @@ test:
try: try:
var rlp = rlpFromBytes(@payload.toRange) var rlp = rlpFromBytes(@payload.toRange)
discard rlp.inspect() discard rlp.inspect()
except RlpError: except RlpError as e:
debug "Inspect failed", err = getCurrentExceptionMsg() debug "Inspect failed", err = e.msg
``` ```
## Supported Fuzzers ## Supported Fuzzers

View File

@ -4,5 +4,5 @@ test:
try: try:
var rlp = rlpFromBytes(@payload.toRange) var rlp = rlpFromBytes(@payload.toRange)
discard rlp.inspect() discard rlp.inspect()
except RlpError: except RlpError as e:
debug "Inspect failed", err = getCurrentExceptionMsg() debug "Inspect failed", err = e.msg