From 4faf35c52c0987277eb5e8fec2965b1127e5f9e6 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 12 Feb 2020 09:40:15 -0500 Subject: [PATCH] throw exception if handshake failed --- libp2p/multistream.nim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libp2p/multistream.nim b/libp2p/multistream.nim index c8b2ff6..a03ee0e 100644 --- a/libp2p/multistream.nim +++ b/libp2p/multistream.nim @@ -38,6 +38,12 @@ type na: string ls: string + MultistreamHandshakeException* = object of CatchableError + +proc newMultistreamHandshakeException*(): ref Exception {.inline.} = + result = newException(MultistreamHandshakeException, + "could not perform multistream handshake") + proc newMultistream*(): MultistreamSelect = new result result.codec = MSCodec @@ -58,8 +64,8 @@ proc select*(m: MultistreamSelect, result = cast[string]((await conn.readLp())) # read ms header result.removeSuffix("\n") if result != Codec: - trace "handshake failed", codec = result.toHex() - return "" + error "handshake failed", codec = result.toHex() + raise newMultistreamHandshakeException() if proto.len() == 0: # no protocols, must be a handshake call return