From 4b34bef33f011e0ad3f7feca1c487132071cc915 Mon Sep 17 00:00:00 2001 From: Janet Cobb Date: Fri, 22 Mar 2024 12:50:25 -0400 Subject: [PATCH] Handle error when retrieving messages while archiving --- .../randomcat/agorabot/util/DefaultArchiver.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/randomcat/agorabot/util/DefaultArchiver.kt b/src/main/kotlin/org/randomcat/agorabot/util/DefaultArchiver.kt index 06cc9dc0..f73b8bc1 100644 --- a/src/main/kotlin/org/randomcat/agorabot/util/DefaultArchiver.kt +++ b/src/main/kotlin/org/randomcat/agorabot/util/DefaultArchiver.kt @@ -624,7 +624,22 @@ private suspend fun archiveChannel( capacity = 100, send = { messageChannel -> withContext(Dispatchers.IO) { - channel.sendForwardHistoryTo(messageChannel) + try { + channel.sendForwardHistoryTo(messageChannel) + } catch (e: Exception) { + val errorPath = basePath.resolve("ERROR_messages.txt") + errorPath.writeText( + e.stackTraceToString(), + options = arrayOf(StandardOpenOption.CREATE_NEW) + ) + + // Resolve ambiguity on getId + val channelSnowflake: ISnowflake = channel + logger.error( + "Failed to get messages when archiving channel ${channelSnowflake.id}", + e + ) + } } }, receive = { messageChannel ->