Merge pull request #138 from status-im/more-exceptions

More explicit Exceptions + fix re-raising
This commit is contained in:
kdeme 2019-12-04 04:28:54 -08:00 committed by GitHub
commit e6164996c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 16 deletions

View File

@ -231,7 +231,7 @@ proc decodeHex(m: string): seq[byte] =
if len(m) > 0:
try:
result = utils.fromHex(m)
except:
except CatchableError:
result = newSeq[byte]()
else:
result = newSeq[byte]()
@ -243,7 +243,7 @@ proc decodeSalt(m: string): string =
sarr = utils.fromHex(m)
result = newString(len(sarr))
copyMem(addr result[0], addr sarr[0], len(sarr))
except:
except CatchableError:
result = ""
else:
result = ""
@ -395,7 +395,7 @@ proc decodeKeyFileJson*(j: JsonNode,
return res
try:
seckey = initPrivateKey(plaintext)
except:
except CatchableError:
return IncorrectPrivateKey
result = Success
else:
@ -414,7 +414,7 @@ proc loadKeyFile*(pathname: string,
try:
data = parseFile(pathname)
result = Success
except:
except CatchableError:
result = JsonError
finally:
stream.close()
@ -432,7 +432,7 @@ proc saveKeyFile*(pathname: string,
try:
f.write($jobject)
result = Success
except:
except CatchableError:
result = OsError
finally:
f.close()

View File

@ -269,7 +269,7 @@ proc processClient(transp: DatagramTransport,
debug "Receive failed", exc = e.name, err = e.msg
except Exception as e:
debug "Receive failed", exc = e.name, err = e.msg
raise
raise e
proc open*(d: DiscoveryProtocol) =
# TODO allow binding to specific IP / IPv6 / etc

View File

@ -87,7 +87,7 @@ proc initENode*(e: string, node: var ENode): ENodeStatus =
tport = parseInt(uri.port)
if tport <= 0 or tport > 65535:
return IncorrectPort
except:
except ValueError:
return IncorrectPort
if len(uri.query) > 0:
@ -97,7 +97,7 @@ proc initENode*(e: string, node: var ENode): ENodeStatus =
uport = parseInt(uri.query[9..^1])
if uport <= 0 or uport > 65535:
return IncorrectDiscPort
except:
except ValueError:
return IncorrectDiscPort
else:
uport = tport
@ -107,12 +107,12 @@ proc initENode*(e: string, node: var ENode): ENodeStatus =
if recoverPublicKey(cast[seq[byte]](data),
node.pubkey) != EthKeysStatus.Success:
return IncorrectNodeId
except:
except CatchableError:
return IncorrectNodeId
try:
node.address.ip = parseIpAddress(uri.hostname)
except:
except ValueError:
zeroMem(addr node.pubkey, KeyLength * 2)
return IncorrectIP

View File

@ -73,7 +73,7 @@ proc requestResolver[MsgType](msg: pointer, future: FutureBase) {.gcsafe.} =
trace "Transport got closed during request"
except Exception as e:
debug "Exception in requestResolver()", exc = e.name, err = e.msg
raise
raise e
proc linkSendFailureToReqFuture[S, R](sendFut: Future[S], resFut: Future[R]) =
sendFut.addCallback() do (arg: pointer):

View File

@ -169,7 +169,7 @@ proc run(p: PeerPool) {.async.} =
var dropConnections = false
try:
await p.maybeConnectToMorePeers()
except Exception as e:
except CatchableError as e:
# Most unexpected errors should be transient, so we log and restart from
# scratch.
error "Unexpected PeerPool error, restarting",

View File

@ -270,9 +270,9 @@ proc sendMsg*(peer: Peer, data: Bytes) {.gcsafe, async.} =
if res != len(cipherText):
# This is ECONNRESET or EPIPE case when remote peer disconnected.
await peer.disconnect(TcpError)
except:
except CatchableError as e:
await peer.disconnect(TcpError)
raise
raise e
proc send*[Msg](peer: Peer, msg: Msg): Future[void] =
logSentMsg(peer, msg)
@ -450,7 +450,7 @@ proc checkedRlpRead(peer: Peer, r: var Rlp, MsgType: type): auto {.inline.} =
exception = e.msg
# rlpData = r.inspect
raise
raise e
proc waitSingleMsg(peer: Peer, MsgType: type): Future[MsgType] {.async.} =
let wantedId = peer.perPeerMsgId(MsgType)

View File

@ -49,6 +49,6 @@ proc testPayloads(filename: string) =
testThunk(payload)
except CatchableError as e:
check: e.name == error.str
raise
raise e
testPayloads(sourceDir / "test_rlpx_thunk.json")