handle exceptions correctly
This commit is contained in:
parent
0347a8ef1d
commit
fc36de21c1
|
@ -7,7 +7,7 @@
|
||||||
## This file may not be copied, modified, or distributed except according to
|
## This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
## those terms.
|
||||||
|
|
||||||
import chronos, options
|
import chronos, options, chronicles
|
||||||
import peerinfo,
|
import peerinfo,
|
||||||
multiaddress,
|
multiaddress,
|
||||||
stream/lpstream,
|
stream/lpstream,
|
||||||
|
@ -101,9 +101,8 @@ proc readLp*(s: Connection): Future[seq[byte]] {.async, gcsafe.} =
|
||||||
buffer.setLen(size)
|
buffer.setLen(size)
|
||||||
if size > 0.uint:
|
if size > 0.uint:
|
||||||
await s.readExactly(addr buffer[0], int(size))
|
await s.readExactly(addr buffer[0], int(size))
|
||||||
except TransportIncompleteError:
|
except LPStreamIncompleteError, LPStreamReadError:
|
||||||
buffer.setLen(0)
|
debug "readLp: could not read from remote", exception = getCurrentExceptionMsg()
|
||||||
except AsyncStreamIncompleteError:
|
|
||||||
buffer.setLen(0)
|
buffer.setLen(0)
|
||||||
|
|
||||||
result = buffer
|
result = buffer
|
||||||
|
@ -118,3 +117,7 @@ proc writeLp*(s: Connection, msg: string | seq[byte]): Future[void] {.gcsafe.} =
|
||||||
method getObservedAddrs*(c: Connection): Future[MultiAddress] {.base, async, gcsafe.} =
|
method getObservedAddrs*(c: Connection): Future[MultiAddress] {.base, async, gcsafe.} =
|
||||||
## get resolved multiaddresses for the connection
|
## get resolved multiaddresses for the connection
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
proc `$`*(conn: Connection): string =
|
||||||
|
if conn.peerInfo.isSome:
|
||||||
|
result = $(conn.peerInfo.get().peerId)
|
||||||
|
|
|
@ -36,7 +36,7 @@ method readExactly*(s: ChronosStream,
|
||||||
nbytes: int): Future[void] {.async, gcsafe.} =
|
nbytes: int): Future[void] {.async, gcsafe.} =
|
||||||
try:
|
try:
|
||||||
await s.reader.readExactly(pbytes, nbytes)
|
await s.reader.readExactly(pbytes, nbytes)
|
||||||
except TransportIncompleteError, AsyncStreamIncompleteError:
|
except AsyncStreamIncompleteError:
|
||||||
raise newLPStreamIncompleteError()
|
raise newLPStreamIncompleteError()
|
||||||
except AsyncStreamReadError as exc:
|
except AsyncStreamReadError as exc:
|
||||||
raise newLPStreamReadError(exc.par)
|
raise newLPStreamReadError(exc.par)
|
||||||
|
|
Loading…
Reference in New Issue