From ca51e151b9e00817731c330062b0812a6cf994fc Mon Sep 17 00:00:00 2001 From: Maddiaa <47148561+Maddiaa0@users.noreply.github.com> Date: Fri, 20 Dec 2024 02:52:54 +0800 Subject: [PATCH] fix(p2p): less verbose error (#10886) copied from lodestar, hopefully prevent the multiline log lines --- yarn-project/p2p/src/services/peer_manager.ts | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/yarn-project/p2p/src/services/peer_manager.ts b/yarn-project/p2p/src/services/peer_manager.ts index 0e39c71b0c7..cd4451b55cd 100644 --- a/yarn-project/p2p/src/services/peer_manager.ts +++ b/yarn-project/p2p/src/services/peer_manager.ts @@ -233,6 +233,7 @@ export class PeerManager implements Traceable { this.logger.trace(`Failed to dial peer ${id} (attempt ${peer.dialAttempts})`, { error: inspect(error) }); this.cachedPeers.set(id, peer); } else { + formatLibp2pDialError(error as Error); this.logger.debug(`Failed to dial peer ${id} (dropping)`, { error: inspect(error) }); this.cachedPeers.delete(id); } @@ -267,3 +268,46 @@ export class PeerManager implements Traceable { } } } + +/** + * copied from github.com/ChainSafe/lodestar + * libp2p errors with extremely noisy errors here, which are deeply nested taking 30-50 lines. + * Some known errors: + * ``` + * Error: The operation was aborted + * Error: stream ended before 1 bytes became available + * Error: Error occurred during XX handshake: Error occurred while verifying signed payload: Peer ID doesn't match libp2p public key + * ``` + * + * Also the error's message is not properly formatted, where the error message is indented and includes the full stack + * ``` + * { + * emessage: '\n' + + * ' Error: stream ended before 1 bytes became available\n' + + * ' at /home/lion/Code/eth2.0/lodestar/node_modules/it-reader/index.js:37:9\n' + + * ' at runMicrotasks ()\n' + + * ' at decoder (/home/lion/Code/eth2.0/lodestar/node_modules/it-length-prefixed/src/decode.js:113:22)\n' + + * ' at first (/home/lion/Code/eth2.0/lodestar/node_modules/it-first/index.js:11:20)\n' + + * ' at Object.exports.read (/home/lion/Code/eth2.0/lodestar/node_modules/multistream-select/src/multistream.js:31:15)\n' + + * ' at module.exports (/home/lion/Code/eth2.0/lodestar/node_modules/multistream-select/src/select.js:21:19)\n' + + * ' at Upgrader._encryptOutbound (/home/lion/Code/eth2.0/lodestar/node_modules/libp2p/src/upgrader.js:397:36)\n' + + * ' at Upgrader.upgradeOutbound (/home/lion/Code/eth2.0/lodestar/node_modules/libp2p/src/upgrader.js:176:11)\n' + + * ' at ClassIsWrapper.dial (/home/lion/Code/eth2.0/lodestar/node_modules/libp2p-tcp/src/index.js:49:18)' + * } + * ``` + * + * Tracking issue https://github.com/libp2p/js-libp2p/issues/996 + */ +function formatLibp2pDialError(e: Error): void { + const errorMessage = e.message.trim(); + const newlineIndex = errorMessage.indexOf('\n'); + e.message = newlineIndex !== -1 ? errorMessage.slice(0, newlineIndex) : errorMessage; + + if ( + e.message.includes('The operation was aborted') || + e.message.includes('stream ended before 1 bytes became available') || + e.message.includes('The operation was aborted') + ) { + e.stack = undefined; + } +}