Skip to content

Commit

Permalink
[lib] make sure useSendComposableDMOperation will not throw
Browse files Browse the repository at this point in the history
Summary:
Fix for [ENG-9312](https://linear.app/comm/issue/ENG-9312/creating-a-new-thick-thread-on-native-results-in-a-message-being).

Depends on D13376

Test Plan: Test case described in ENG-9312

Reviewers: tomek, bartek

Reviewed By: tomek, bartek

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D13384
  • Loading branch information
xsanm committed Sep 19, 2024
1 parent d1a5df1 commit 395b354
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions lib/shared/dm-ops/process-dm-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,19 @@ function useSendComposableDMOperation(): (
localMessageInfo.outboundP2PMessageIDs.length > 0
) {
processOutboundMessages(localMessageInfo.outboundP2PMessageIDs, dmOpID);
return promise;
try {
// This code should never throw.
return await promise;
} catch (e) {
invariant(
localMessageInfo.outboundP2PMessageIDs,
'outboundP2PMessageIDs should be defined',
);
return {
result: 'failure',
failedMessageIDs: localMessageInfo.outboundP2PMessageIDs,
};
}
}

const outboundP2PMessages = await createMessagesToPeersFromDMOp(
Expand Down Expand Up @@ -382,7 +394,17 @@ function useSendComposableDMOperation(): (
},
);

return promise;
try {
// This code should never throw.
return await promise;
} catch (e) {
return {
result: 'failure',
failedMessageIDs: outboundP2PMessages.map(
message => message.messageID,
),
};
}
},
[
allPeerUserIDAndDeviceIDs,
Expand Down

0 comments on commit 395b354

Please sign in to comment.