mirror of https://github.com/status-im/nim-eth.git
Use different try/except construct to enforce returning on error
This commit is contained in:
parent
23aa13b03d
commit
ffb7923370
|
@ -408,30 +408,25 @@ proc receive*(d: Protocol, a: Address, packet: openArray[byte]) {.gcsafe,
|
||||||
proc processClient(transp: DatagramTransport, raddr: TransportAddress):
|
proc processClient(transp: DatagramTransport, raddr: TransportAddress):
|
||||||
Future[void] {.async, gcsafe, raises: [Exception, Defect].} =
|
Future[void] {.async, gcsafe, raises: [Exception, Defect].} =
|
||||||
let proto = getUserData[Protocol](transp)
|
let proto = getUserData[Protocol](transp)
|
||||||
var ip: IpAddress
|
|
||||||
var buf = newSeq[byte]()
|
|
||||||
|
|
||||||
try:
|
# TODO: should we use `peekMessage()` to avoid allocation?
|
||||||
# TODO: should we use `peekMessage()` to avoid allocation?
|
# TODO: This can still raise general `Exception` while it probably should
|
||||||
# TODO: This can still raise general `Exception` while it probably should
|
# only give TransportOsError.
|
||||||
# only give TransportOsError.
|
let buf = try: transp.getMessage()
|
||||||
buf = transp.getMessage()
|
except TransportOsError as e:
|
||||||
except TransportOsError as e:
|
# This is likely to be local network connection issues.
|
||||||
# This is likely to be local network connection issues.
|
error "Transport getMessage", exception = e.name, msg = e.msg
|
||||||
error "Transport getMessage error", exception = e.name, msg = e.msg
|
return
|
||||||
return
|
except Exception as e:
|
||||||
except Exception as e:
|
if e of Defect:
|
||||||
if e of Defect:
|
raise (ref Defect)(e)
|
||||||
raise (ref Defect)(e)
|
else: doAssert(false)
|
||||||
else: doAssert(false)
|
return # Make compiler happy
|
||||||
|
|
||||||
try:
|
|
||||||
ip = raddr.address()
|
|
||||||
except ValueError:
|
|
||||||
# This should not be possible considering we bind to an IP address.
|
|
||||||
error "Not a valid IpAddress"
|
|
||||||
return
|
|
||||||
|
|
||||||
|
let ip = try: raddr.address()
|
||||||
|
except ValueError as e:
|
||||||
|
error "Not a valid IpAddress", exception = e.name, msg = e.msg
|
||||||
|
return
|
||||||
let a = Address(ip: ValidIpAddress.init(ip), port: raddr.port)
|
let a = Address(ip: ValidIpAddress.init(ip), port: raddr.port)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue