mirror of https://github.com/status-im/nim-eth.git
More explicit Exceptions + fix re-raising
This commit is contained in:
parent
146eeddd65
commit
0229547c41
|
@ -231,7 +231,7 @@ proc decodeHex(m: string): seq[byte] =
|
||||||
if len(m) > 0:
|
if len(m) > 0:
|
||||||
try:
|
try:
|
||||||
result = utils.fromHex(m)
|
result = utils.fromHex(m)
|
||||||
except:
|
except CatchableError:
|
||||||
result = newSeq[byte]()
|
result = newSeq[byte]()
|
||||||
else:
|
else:
|
||||||
result = newSeq[byte]()
|
result = newSeq[byte]()
|
||||||
|
@ -243,7 +243,7 @@ proc decodeSalt(m: string): string =
|
||||||
sarr = utils.fromHex(m)
|
sarr = utils.fromHex(m)
|
||||||
result = newString(len(sarr))
|
result = newString(len(sarr))
|
||||||
copyMem(addr result[0], addr sarr[0], len(sarr))
|
copyMem(addr result[0], addr sarr[0], len(sarr))
|
||||||
except:
|
except CatchableError:
|
||||||
result = ""
|
result = ""
|
||||||
else:
|
else:
|
||||||
result = ""
|
result = ""
|
||||||
|
@ -395,7 +395,7 @@ proc decodeKeyFileJson*(j: JsonNode,
|
||||||
return res
|
return res
|
||||||
try:
|
try:
|
||||||
seckey = initPrivateKey(plaintext)
|
seckey = initPrivateKey(plaintext)
|
||||||
except:
|
except CatchableError:
|
||||||
return IncorrectPrivateKey
|
return IncorrectPrivateKey
|
||||||
result = Success
|
result = Success
|
||||||
else:
|
else:
|
||||||
|
@ -414,7 +414,7 @@ proc loadKeyFile*(pathname: string,
|
||||||
try:
|
try:
|
||||||
data = parseFile(pathname)
|
data = parseFile(pathname)
|
||||||
result = Success
|
result = Success
|
||||||
except:
|
except CatchableError:
|
||||||
result = JsonError
|
result = JsonError
|
||||||
finally:
|
finally:
|
||||||
stream.close()
|
stream.close()
|
||||||
|
@ -432,7 +432,7 @@ proc saveKeyFile*(pathname: string,
|
||||||
try:
|
try:
|
||||||
f.write($jobject)
|
f.write($jobject)
|
||||||
result = Success
|
result = Success
|
||||||
except:
|
except CatchableError:
|
||||||
result = OsError
|
result = OsError
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
|
@ -269,7 +269,7 @@ proc processClient(transp: DatagramTransport,
|
||||||
debug "Receive failed", exc = e.name, err = e.msg
|
debug "Receive failed", exc = e.name, err = e.msg
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
debug "Receive failed", exc = e.name, err = e.msg
|
debug "Receive failed", exc = e.name, err = e.msg
|
||||||
raise
|
raise e
|
||||||
|
|
||||||
proc open*(d: DiscoveryProtocol) =
|
proc open*(d: DiscoveryProtocol) =
|
||||||
# TODO allow binding to specific IP / IPv6 / etc
|
# TODO allow binding to specific IP / IPv6 / etc
|
||||||
|
|
|
@ -87,7 +87,7 @@ proc initENode*(e: string, node: var ENode): ENodeStatus =
|
||||||
tport = parseInt(uri.port)
|
tport = parseInt(uri.port)
|
||||||
if tport <= 0 or tport > 65535:
|
if tport <= 0 or tport > 65535:
|
||||||
return IncorrectPort
|
return IncorrectPort
|
||||||
except:
|
except ValueError:
|
||||||
return IncorrectPort
|
return IncorrectPort
|
||||||
|
|
||||||
if len(uri.query) > 0:
|
if len(uri.query) > 0:
|
||||||
|
@ -97,7 +97,7 @@ proc initENode*(e: string, node: var ENode): ENodeStatus =
|
||||||
uport = parseInt(uri.query[9..^1])
|
uport = parseInt(uri.query[9..^1])
|
||||||
if uport <= 0 or uport > 65535:
|
if uport <= 0 or uport > 65535:
|
||||||
return IncorrectDiscPort
|
return IncorrectDiscPort
|
||||||
except:
|
except ValueError:
|
||||||
return IncorrectDiscPort
|
return IncorrectDiscPort
|
||||||
else:
|
else:
|
||||||
uport = tport
|
uport = tport
|
||||||
|
@ -107,12 +107,12 @@ proc initENode*(e: string, node: var ENode): ENodeStatus =
|
||||||
if recoverPublicKey(cast[seq[byte]](data),
|
if recoverPublicKey(cast[seq[byte]](data),
|
||||||
node.pubkey) != EthKeysStatus.Success:
|
node.pubkey) != EthKeysStatus.Success:
|
||||||
return IncorrectNodeId
|
return IncorrectNodeId
|
||||||
except:
|
except CatchableError:
|
||||||
return IncorrectNodeId
|
return IncorrectNodeId
|
||||||
|
|
||||||
try:
|
try:
|
||||||
node.address.ip = parseIpAddress(uri.hostname)
|
node.address.ip = parseIpAddress(uri.hostname)
|
||||||
except:
|
except ValueError:
|
||||||
zeroMem(addr node.pubkey, KeyLength * 2)
|
zeroMem(addr node.pubkey, KeyLength * 2)
|
||||||
return IncorrectIP
|
return IncorrectIP
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ proc requestResolver[MsgType](msg: pointer, future: FutureBase) {.gcsafe.} =
|
||||||
trace "Transport got closed during request"
|
trace "Transport got closed during request"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
debug "Exception in requestResolver()", exc = e.name, err = e.msg
|
debug "Exception in requestResolver()", exc = e.name, err = e.msg
|
||||||
raise
|
raise e
|
||||||
|
|
||||||
proc linkSendFailureToReqFuture[S, R](sendFut: Future[S], resFut: Future[R]) =
|
proc linkSendFailureToReqFuture[S, R](sendFut: Future[S], resFut: Future[R]) =
|
||||||
sendFut.addCallback() do (arg: pointer):
|
sendFut.addCallback() do (arg: pointer):
|
||||||
|
|
|
@ -169,7 +169,7 @@ proc run(p: PeerPool) {.async.} =
|
||||||
var dropConnections = false
|
var dropConnections = false
|
||||||
try:
|
try:
|
||||||
await p.maybeConnectToMorePeers()
|
await p.maybeConnectToMorePeers()
|
||||||
except Exception as e:
|
except CatchableError as e:
|
||||||
# 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",
|
||||||
|
|
|
@ -270,9 +270,9 @@ proc sendMsg*(peer: Peer, data: Bytes) {.gcsafe, async.} =
|
||||||
if res != len(cipherText):
|
if res != len(cipherText):
|
||||||
# This is ECONNRESET or EPIPE case when remote peer disconnected.
|
# This is ECONNRESET or EPIPE case when remote peer disconnected.
|
||||||
await peer.disconnect(TcpError)
|
await peer.disconnect(TcpError)
|
||||||
except:
|
except CatchableError as e:
|
||||||
await peer.disconnect(TcpError)
|
await peer.disconnect(TcpError)
|
||||||
raise
|
raise e
|
||||||
|
|
||||||
proc send*[Msg](peer: Peer, msg: Msg): Future[void] =
|
proc send*[Msg](peer: Peer, msg: Msg): Future[void] =
|
||||||
logSentMsg(peer, msg)
|
logSentMsg(peer, msg)
|
||||||
|
@ -450,7 +450,7 @@ proc checkedRlpRead(peer: Peer, r: var Rlp, MsgType: type): auto {.inline.} =
|
||||||
exception = e.msg
|
exception = e.msg
|
||||||
# rlpData = r.inspect
|
# rlpData = r.inspect
|
||||||
|
|
||||||
raise
|
raise e
|
||||||
|
|
||||||
proc waitSingleMsg(peer: Peer, MsgType: type): Future[MsgType] {.async.} =
|
proc waitSingleMsg(peer: Peer, MsgType: type): Future[MsgType] {.async.} =
|
||||||
let wantedId = peer.perPeerMsgId(MsgType)
|
let wantedId = peer.perPeerMsgId(MsgType)
|
||||||
|
|
|
@ -49,6 +49,6 @@ proc testPayloads(filename: string) =
|
||||||
testThunk(payload)
|
testThunk(payload)
|
||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
check: e.name == error.str
|
check: e.name == error.str
|
||||||
raise
|
raise e
|
||||||
|
|
||||||
testPayloads(sourceDir / "test_rlpx_thunk.json")
|
testPayloads(sourceDir / "test_rlpx_thunk.json")
|
||||||
|
|
Loading…
Reference in New Issue