From 1ffde55beb6604d02e7ace5e7525a206fdbd57f1 Mon Sep 17 00:00:00 2001 From: Marco Cirillo Date: Thu, 25 Jul 2024 01:14:11 +0200 Subject: [PATCH] Do not interrupt redact sequences because of exceptions on backfilling (#479) --- src/utils.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 5e9899b..40f3244 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -86,16 +86,20 @@ export async function redactUserMessagesIn(client: MatrixSendClient, managementR for (const targetRoomId of targetRoomIds) { await managementRoom.logMessage(LogLevel.DEBUG, "utils#redactUserMessagesIn", `Fetching sent messages for ${userIdOrGlob} in ${targetRoomId} to redact...`, targetRoomId); - await getMessagesByUserIn(client, userIdOrGlob, targetRoomId, limit, async (eventsToRedact) => { - for (const targetEvent of eventsToRedact) { - await managementRoom.logMessage(LogLevel.DEBUG, "utils#redactUserMessagesIn", `Redacting ${targetEvent['event_id']} in ${targetRoomId}`, targetRoomId); - if (!noop) { - await client.redactEvent(targetRoomId, targetEvent['event_id']); - } else { - await managementRoom.logMessage(LogLevel.WARN, "utils#redactUserMessagesIn", `Tried to redact ${targetEvent['event_id']} in ${targetRoomId} but Mjolnir is running in no-op mode`, targetRoomId); + try { + await getMessagesByUserIn(client, userIdOrGlob, targetRoomId, limit, async (eventsToRedact) => { + for (const targetEvent of eventsToRedact) { + await managementRoom.logMessage(LogLevel.DEBUG, "utils#redactUserMessagesIn", `Redacting ${targetEvent['event_id']} in ${targetRoomId}`, targetRoomId); + if (!noop) { + await client.redactEvent(targetRoomId, targetEvent['event_id']); + } else { + await managementRoom.logMessage(LogLevel.WARN, "utils#redactUserMessagesIn", `Tried to redact ${targetEvent['event_id']} in ${targetRoomId} but Mjolnir is running in no-op mode`, targetRoomId); + } } - } - }); + }); + } catch (error) { + await managementRoom.logMessage(LogLevel.ERROR, "utils#redactUserMessagesIn", `Caught an error while trying to redact messages for ${userIdOrGlob} in ${targetRoomId}: ${error}`, targetRoomId); + } } }