From 6316b07e8138729a904f86ee4a23a588876db7a2 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 12 Feb 2020 09:40:54 -0500 Subject: [PATCH] don't crash when stringifying nil peerinfo --- libp2p/peerinfo.nim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libp2p/peerinfo.nim b/libp2p/peerinfo.nim index 4bc562b..9d4c17d 100644 --- a/libp2p/peerinfo.nim +++ b/libp2p/peerinfo.nim @@ -105,9 +105,13 @@ proc publicKey*(p: PeerInfo): Option[PublicKey] {.inline.} = result = some(p.privateKey.getKey()) proc id*(p: PeerInfo): string {.inline.} = - result = p.peerId.pretty() + if not isNil(p): + result = p.peerId.pretty() proc `$`*(p: PeerInfo): string = + if isNil(p): + return "" + result.add("PeerID: ") result.add(p.id & "\n")