better exceptions
This commit is contained in:
parent
95774b2b81
commit
7ff76d76b6
|
@ -39,7 +39,7 @@ type
|
||||||
|
|
||||||
MultistreamHandshakeException* = object of CatchableError
|
MultistreamHandshakeException* = object of CatchableError
|
||||||
|
|
||||||
proc newMultistreamHandshakeException*(): ref Exception {.inline.} =
|
proc newMultistreamHandshakeException*(): ref CatchableError {.inline.} =
|
||||||
result = newException(MultistreamHandshakeException,
|
result = newException(MultistreamHandshakeException,
|
||||||
"could not perform multistream handshake")
|
"could not perform multistream handshake")
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ proc list*(m: MultistreamSelect,
|
||||||
|
|
||||||
proc handle*(m: MultistreamSelect, conn: Connection) {.async, gcsafe.} =
|
proc handle*(m: MultistreamSelect, conn: Connection) {.async, gcsafe.} =
|
||||||
trace "handle: starting multistream handling"
|
trace "handle: starting multistream handling"
|
||||||
tryAndWarn "multistream handle":
|
try:
|
||||||
while not conn.closed:
|
while not conn.closed:
|
||||||
var ms = string.fromBytes(await conn.readLp(1024))
|
var ms = string.fromBytes(await conn.readLp(1024))
|
||||||
ms.removeSuffix("\n")
|
ms.removeSuffix("\n")
|
||||||
|
@ -142,14 +142,14 @@ proc handle*(m: MultistreamSelect, conn: Connection) {.async, gcsafe.} =
|
||||||
if (not isNil(h.match) and h.match(ms)) or ms == h.proto:
|
if (not isNil(h.match) and h.match(ms)) or ms == h.proto:
|
||||||
trace "found handler for", protocol = ms
|
trace "found handler for", protocol = ms
|
||||||
await conn.writeLp((h.proto & "\n"))
|
await conn.writeLp((h.proto & "\n"))
|
||||||
tryAndWarn "multistream handle handler":
|
await h.protocol.handler(conn, ms)
|
||||||
await h.protocol.handler(conn, ms)
|
return
|
||||||
return
|
|
||||||
warn "no handlers for ", protocol = ms
|
warn "no handlers for ", protocol = ms
|
||||||
await conn.write(Na)
|
await conn.write(Na)
|
||||||
trace "leaving multistream loop"
|
except CatchableError as exc:
|
||||||
# we might be tempted to close conn here but that would be a bad idea!
|
trace "exception in multistream", exc = exc.msg
|
||||||
# we indeed will reuse it later on
|
finally:
|
||||||
|
trace "leaving multistream loop"
|
||||||
|
|
||||||
proc addHandler*[T: LPProtocol](m: MultistreamSelect,
|
proc addHandler*[T: LPProtocol](m: MultistreamSelect,
|
||||||
codec: string,
|
codec: string,
|
||||||
|
|
Loading…
Reference in New Issue