Skip to content

chore: use %e token anywhere we are logging errors with @libp2p/logger #3175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/interface-compliance-tests/src/mocks/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,12 @@ export function mockConnection (maConn: MultiaddrConnection, opts: MockConnectio
const { handler } = registrar.getHandler(protocol)

handler({ connection, stream: muxedStream })
}).catch(err => {
log.error(err)
})
.catch(err => {
log.error('incoming stream handler error - %e', err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to add more context to this message but there is an unrelated formatting change, please keep the additional context but revert the reformatting.

})
} catch (err: any) {
log.error(err)
log.error('error handling incoming stream - %e', err)
}
},
onStreamEnd: (muxedStream) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/kad-dht/src/query/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export class QueryManager implements Startable {
// Execute the query along each disjoint path and yield their results as they become available
for await (const event of merge(...paths)) {
if (event.name === 'QUERY_ERROR') {
log.error('query error', event.error)
log.error('query error - %e', event.error)
}

if (event.name === 'PEER_RESPONSE') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export async function initiateConnection ({ rtcConfiguration, dataChannel, signa

// create an offer
const offerSdp = await peerConnection.createOffer().catch(err => {
log.error('could not execute createOffer', err)
log.error('could not execute createOffer - %e', err)
throw new SDPHandshakeFailedError('Failed to set createOffer')
})

Expand All @@ -134,7 +134,7 @@ export async function initiateConnection ({ rtcConfiguration, dataChannel, signa

// set offer as local description
await peerConnection.setLocalDescription(offerSdp).catch(err => {
log.error('could not execute setLocalDescription', err)
log.error('could not execute setLocalDescription - %e', err)
throw new SDPHandshakeFailedError('Failed to set localDescription')
})

Expand All @@ -155,7 +155,7 @@ export async function initiateConnection ({ rtcConfiguration, dataChannel, signa

const answerSdp = new RTCSessionDescription({ type: 'answer', sdp: answerMessage.data })
await peerConnection.setRemoteDescription(answerSdp).catch(err => {
log.error('could not execute setRemoteDescription', err)
log.error('could not execute setRemoteDescription - %e', err)
throw new SDPHandshakeFailedError('Failed to set remoteDescription')
})

Expand Down Expand Up @@ -188,7 +188,7 @@ export async function initiateConnection ({ rtcConfiguration, dataChannel, signa
muxerFactory
}
} catch (err: any) {
log.error('outgoing signaling error', err)
log.error('outgoing signaling error - %e', err)

peerConnection.close()
stream.abort(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function handleIncomingStream ({ peerConnection, stream, signal, co
signal
})
.catch(err => {
log.error('error sending ICE candidate', err)
log.error('error sending ICE candidate - %e', err)
})
}

Expand All @@ -60,13 +60,13 @@ export async function handleIncomingStream ({ peerConnection, stream, signal, co
})

await peerConnection.setRemoteDescription(offer).catch(err => {
log.error('could not execute setRemoteDescription', err)
log.error('could not execute setRemoteDescription - %e', err)
throw new SDPHandshakeFailedError('Failed to set remoteDescription')
})

// create and write an SDP answer
const answer = await peerConnection.createAnswer().catch(err => {
log.error('could not execute createAnswer', err)
log.error('could not execute createAnswer - %e', err)
throw new SDPHandshakeFailedError('Failed to create answer')
})

Expand All @@ -78,7 +78,7 @@ export async function handleIncomingStream ({ peerConnection, stream, signal, co
})

await peerConnection.setLocalDescription(answer).catch(err => {
log.error('could not execute setLocalDescription', err)
log.error('could not execute setLocalDescription - %e', err)
throw new SDPHandshakeFailedError('Failed to set localDescription')
})

Expand All @@ -93,7 +93,6 @@ export async function handleIncomingStream ({ peerConnection, stream, signal, co
} catch (err: any) {
if (getConnectionState(peerConnection) !== 'connected') {
log.error('error while handling signaling stream from peer %a', connection.remoteAddr, err)

peerConnection.close()
throw err
} else {
Expand Down
6 changes: 3 additions & 3 deletions packages/transport-webtransport/src/muxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export function webtransportMuxer (wt: Pick<WebTransport, 'close' | 'createBidir
log(`too many inbound streams open - ${activeStreams.length}/${config.maxInboundStreams}, closing new incoming stream`)
// We've reached our limit, close this stream.
wtStream.writable.close().catch((err: Error) => {
log.error(`failed to close inbound stream that crossed our maxInboundStream limit: ${err.message}`)
log.error('failed to close inbound stream that crossed our maxInboundStream limit - %e', err)
})
wtStream.readable.cancel().catch((err: Error) => {
log.error(`failed to close inbound stream that crossed our maxInboundStream limit: ${err.message}`)
log.error('failed to close inbound stream that crossed our maxInboundStream limit - %e', err)
})
} else {
const stream = await webtransportBiDiStreamToStream(
Expand All @@ -57,7 +57,7 @@ export function webtransportMuxer (wt: Pick<WebTransport, 'close' | 'createBidir
}
})
.catch(err => {
log.error('could not create a new stream', err)
log.error('could not create a new stream - %e', err)
})

const muxer: StreamMuxer = {
Expand Down