Skip to content

Commit e10c5c0

Browse files
fix: update error logs to use %e token (#3261)
Ensure errors are logged using the %e token across the codebase to get stack traces printed correctly. Fixes #3161 --------- Co-authored-by: Alex Potsides <alex@achingbrain.net>
1 parent 8d66d5f commit e10c5c0

File tree

52 files changed

+117
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+117
-119
lines changed

packages/connection-encrypter-plaintext/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ class Plaintext implements ConnectionEncrypter {
104104
throw new InvalidCryptoExchangeError('Public key did not match id')
105105
}
106106
} catch (err: any) {
107-
log.error(err)
108-
throw new InvalidCryptoExchangeError('Invalid public key - ' + err.message)
107+
log.error('invalid public key - %e', err)
108+
throw new InvalidCryptoExchangeError(`Invalid public key - ${err.message}`)
109109
}
110110

111111
if (options?.remotePeer != null && !peerId.equals(options?.remotePeer)) {

packages/connection-encrypter-tls/src/tls.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class TLS implements ConnectionEncrypter {
179179

180180
if (streamMuxer == null) {
181181
const err = new InvalidCryptoExchangeError(`Selected muxer ${socket.alpnProtocol} did not exist`)
182-
log.error(`Selected muxer ${socket.alpnProtocol} did not exist - %e`, err)
182+
log.error('selected muxer %s did not exist - %e', socket.alpnProtocol, err)
183183

184184
connection.abort(err)
185185
reject(err)

packages/floodsub/src/floodsub.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export class FloodSub extends TypedEventEmitter<FloodSubEvents> implements Flood
341341

342342
await this.processMessage(peerStream.peerId, msg)
343343
} catch (err: any) {
344-
this.log.error(err)
344+
this.log.error('failed to queue messages from %p - %e', peerStream.peerId, err)
345345
}
346346
}))
347347
.catch(err => { this.log(err) })
@@ -466,15 +466,15 @@ export class FloodSub extends TypedEventEmitter<FloodSubEvents> implements Flood
466466
* Send an rpc object to a peer
467467
*/
468468
sendRpc (peer: PeerId, rpc: PubSubRPC): void {
469-
const peerStream = this.peers.get(peer)
469+
const peerStreams = this.peers.get(peer)
470470

471-
if (peerStream == null) {
472-
this.log.error('Cannot send RPC to %p as there are no streams to it available', peer)
471+
if (peerStreams == null) {
472+
this.log.error('cannot send RPC to %p as there are no streams to it available', peer)
473473

474474
return
475475
}
476476

477-
peerStream.write(rpc)
477+
peerStreams.write(rpc)
478478
}
479479

480480
/**

packages/kad-dht/src/content-fetching/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class ContentFetching {
106106
this.log(`Storing corrected record for key ${dsKey.toString()}`)
107107
await this.components.datastore.put(dsKey, fixupRec.subarray(), options)
108108
} catch (err: any) {
109-
this.log.error('Failed error correcting self', err)
109+
this.log.error('failed error correcting self - %e', err)
110110
}
111111

112112
continue
@@ -132,7 +132,7 @@ export class ContentFetching {
132132
throw new QueryError('Could not send correction')
133133
}
134134

135-
this.log.error('Failed error correcting entry')
135+
this.log.error('failed error correcting entry')
136136
}
137137
}
138138

packages/kad-dht/src/content-routing/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class ContentRouting {
115115
yield addProviderEvent
116116
}
117117
} catch (err: any) {
118-
self.log.error('error sending provide record to peer %p', event.peer.id, err)
118+
self.log.error('error sending provide record to peer %p - %e', event.peer.id, err)
119119
yield queryErrorEvent({
120120
from: event.peer.id,
121121
error: err,

packages/kad-dht/src/kad-dht.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export class KadDHT extends TypedEventEmitter<PeerDiscoveryEvents> implements Ka
298298
const peerData = evt.detail
299299

300300
this.onPeerConnect(peerData).catch(err => {
301-
this.log.error('could not add %p to routing table', peerData.id, err)
301+
this.log.error('could not add %p to routing table - %e', peerData.id, err)
302302
})
303303

304304
this.dispatchEvent(new CustomEvent('peer', {
@@ -321,7 +321,7 @@ export class KadDHT extends TypedEventEmitter<PeerDiscoveryEvents> implements Ka
321321

322322
await this.onPeerConnect(peerData)
323323
}).catch(err => {
324-
this.log.error('could not add %p to routing table - %e - %e', peerId, err)
324+
this.log.error('could not add %p to routing table - %e', peerId, err)
325325
})
326326
})
327327

@@ -350,7 +350,7 @@ export class KadDHT extends TypedEventEmitter<PeerDiscoveryEvents> implements Ka
350350
}
351351
})
352352
.catch(err => {
353-
this.log.error('error setting dht server mode', err)
353+
this.log.error('error setting dht server mode - %e', err)
354354
})
355355
})
356356
}
@@ -407,7 +407,7 @@ export class KadDHT extends TypedEventEmitter<PeerDiscoveryEvents> implements Ka
407407
signal
408408
})
409409
} catch (err: any) {
410-
this.log.error('could not add %p to routing table', peerData.id, err)
410+
this.log.error('could not add %p to routing table - %e', peerData.id, err)
411411
}
412412
}
413413

packages/kad-dht/src/network.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> implements Startab
186186

187187
stream.close(options)
188188
.catch(err => {
189-
this.log.error('error closing stream to %p', to, err)
189+
this.log.error('error closing stream to %p - %e', to, err)
190190
stream?.abort(err)
191191
})
192192

@@ -252,7 +252,7 @@ export class Network extends TypedEventEmitter<NetworkEvents> implements Startab
252252

253253
stream.close(options)
254254
.catch(err => {
255-
this.log.error('error closing stream to %p', to, err)
255+
this.log.error('error closing stream to %p - %e', to, err)
256256
stream?.abort(err)
257257
})
258258

packages/kad-dht/src/query-self.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class QuerySelf implements Startable {
7676
this.timeoutId = setTimeout(() => {
7777
this.querySelf()
7878
.catch(err => {
79-
this.log.error('error running self-query', err)
79+
this.log.error('error running self-query - %e', err)
8080
})
8181
}, this.initialInterval)
8282
}
@@ -146,7 +146,7 @@ export class QuerySelf implements Startable {
146146
}
147147
}))
148148
} catch (err: any) {
149-
this.log.error('self-query error', err)
149+
this.log.error('self-query error - %e', err)
150150
} finally {
151151
signal.clear()
152152

@@ -167,7 +167,7 @@ export class QuerySelf implements Startable {
167167
this.timeoutId = setTimeout(() => {
168168
this.querySelf()
169169
.catch(err => {
170-
this.log.error('error running self-query', err)
170+
this.log.error('error running self-query - %e', err)
171171
})
172172
}, this.interval)
173173
}

packages/kad-dht/src/query/manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export class QueryManager implements Startable {
217217
// Execute the query along each disjoint path and yield their results as they become available
218218
for await (const event of merge(...paths)) {
219219
if (event.name === 'QUERY_ERROR') {
220-
log.error('query error', event.error)
220+
log.error('query error - %e', event.error)
221221
}
222222

223223
if (event.name === 'PEER_RESPONSE') {

packages/kad-dht/src/reprovider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export class Reprovider extends TypedEventEmitter<ReprovideEvents> {
152152
})
153153
}
154154
} catch (err: any) {
155-
this.log.error('error processing datastore key %s - %e', entry.key, err.message)
155+
this.log.error('error processing datastore key %s - %s', entry.key, err.message)
156156
}
157157
}
158158

0 commit comments

Comments
 (0)