diff --git a/lib/tunnelbroker/peer-to-peer-context.js b/lib/tunnelbroker/peer-to-peer-context.js --- a/lib/tunnelbroker/peer-to-peer-context.js +++ b/lib/tunnelbroker/peer-to-peer-context.js @@ -8,6 +8,7 @@ type TunnelbrokerClientMessageToDevice, useTunnelbroker, } from './tunnelbroker-context.js'; +import { useDebugLogs } from '../components/debug-logs-context.js'; import { usePeerOlmSessionsCreatorContext } from '../components/peer-olm-session-creator-provider.react.js'; import { useActionsQueue } from '../hooks/actions-queue.js'; import { useSendPushNotifs } from '../push/send-hooks.react.js'; @@ -69,6 +70,7 @@ userID: string, devices: $ReadOnlyArray<DeviceSessionCreationRequest>, ) => Promise<void>, + addLog: (title: string, message: string) => mixed, ): Promise<void> { const creatingSessionPromises = entries(userDevicesWithoutSession).map( async ([userID, devices]) => { @@ -80,7 +82,10 @@ } catch (e) { // Session creation may fail for some devices, // but we should still pursue delivery for others. - console.log(e); + addLog( + `Error while creating missing session with ${userID}`, + getMessageForException(e) ?? 'unknown error', + ); } }, ); @@ -119,6 +124,7 @@ ) => Promise<void>, messageIDs: ?$ReadOnlyArray<string>, allPeerDevices: $ReadOnlySet<string>, + addLog: (title: string, message: string) => mixed, ): Promise<ProcessOutboundP2PMessagesResult> { let authMetadata; try { @@ -222,7 +228,11 @@ // 4. Create sessions with users who have at least one device // without a session. - await createMissingSession(userDevicesWithoutSession, peerOlmSessionsCreator); + await createMissingSession( + userDevicesWithoutSession, + peerOlmSessionsCreator, + addLog, + ); // 5. Retry messages for which the session was missing. const retryPromises = messagesToRetry.map(message => @@ -251,6 +261,7 @@ function PeerToPeerProvider(props: Props): React.Node { const { children } = props; + const { addLog } = useDebugLogs(); const { sendMessageToDevice } = useTunnelbroker(); const identityContext = React.useContext(IdentityClientContext); invariant(identityContext, 'Identity context should be set'); @@ -299,6 +310,7 @@ peerOlmSessionsCreator, message.outboundMessageIDs, message.allPeerDevices, + addLog, ), sendPushNotifs(message.notificationsCreationData), ]); @@ -321,6 +333,7 @@ } }, [ + addLog, identityContext, peerOlmSessionsCreator, sendMessageToDevice, @@ -396,6 +409,7 @@ await createMissingSession( userDevicesWithoutSession, peerOlmSessionsCreator, + addLog, ); // 4. Retry recipients for which session was missing. @@ -409,7 +423,7 @@ ); await Promise.all(retryPromises); }, - [peerOlmSessionsCreator, sendMessageToDevice], + [addLog, peerOlmSessionsCreator, sendMessageToDevice], ); React.useEffect(() => {