From f4e31019e115de0fffef01bb51a8f8e22c6cc8af Mon Sep 17 00:00:00 2001 From: Danish Arora <35004822+danisharora099@users.noreply.github.com> Date: Thu, 11 May 2023 13:35:58 +0530 Subject: [PATCH] fix: improve logging for connection manager (#1303) * merge: master * fix: CI * use: js script instead of shell script to run precheck and mocha * improve logging when dial fails * use hashmap for errors instead of redeclaring variable --- packages/core/src/lib/connection_manager.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/core/src/lib/connection_manager.ts b/packages/core/src/lib/connection_manager.ts index 985aee696e..e0ba8188c7 100644 --- a/packages/core/src/lib/connection_manager.ts +++ b/packages/core/src/lib/connection_manager.ts @@ -19,6 +19,7 @@ export class ConnectionManager { private options: ConnectionManagerOptions; private libp2pComponents: Libp2p; private dialAttemptsForPeer: Map = new Map(); + private dialErrorsForPeer: Map = new Map(); public static create( peerId: string, @@ -102,9 +103,10 @@ export class ConnectionManager { this.dialAttemptsForPeer.delete(peerId.toString()); return; - } catch (error) { - log(` - Error dialing peer ${peerId.toString()}`); + } catch (error: any) { + this.dialErrorsForPeer.set(peerId.toString(), error); + log(`Error dialing peer ${peerId.toString()} - ${error.errors}`); + dialAttempt = this.dialAttemptsForPeer.get(peerId.toString()) ?? 1; this.dialAttemptsForPeer.set(peerId.toString(), dialAttempt + 1); @@ -115,7 +117,13 @@ export class ConnectionManager { } try { - log(`Deleting undialable peer ${peerId.toString()} from peer store`); + log( + `Deleting undialable peer ${peerId.toString()} from peer store. Error: ${JSON.stringify( + this.dialErrorsForPeer.get(peerId.toString()).errors[0] + )} + }` + ); + this.dialErrorsForPeer.delete(peerId.toString()); return await this.libp2pComponents.peerStore.delete(peerId); } catch (error) { throw `Error deleting undialable peer ${peerId.toString()} from peer store - ${error}`;