From 8020551a6640f282907de42b56836f2ee254334d Mon Sep 17 00:00:00 2001 From: Janet Cobb Date: Tue, 2 Jan 2024 13:29:04 -0500 Subject: [PATCH] Handle error downloading attachment in archive --- .../agorabot/util/DefaultArchiver.kt | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/org/randomcat/agorabot/util/DefaultArchiver.kt b/src/main/kotlin/org/randomcat/agorabot/util/DefaultArchiver.kt index 0d8c2519..884e471d 100644 --- a/src/main/kotlin/org/randomcat/agorabot/util/DefaultArchiver.kt +++ b/src/main/kotlin/org/randomcat/agorabot/util/DefaultArchiver.kt @@ -151,15 +151,24 @@ private suspend fun receivePendingDownloads( val attachmentDir = attachmentsDir.resolve("attachment-$number") attachmentDir.createDirectory() - val outPath = attachmentDir.resolve(fileName) + try { + val outPath = attachmentDir.resolve(fileName) - logger.info("Downloading channel $channelId attachment $number: $fileName") + logger.info("Downloading channel $channelId attachment $number; name: $fileName; url: ${pendingDownload.attachment.url}") - outPath.outputStream(StandardOpenOption.CREATE_NEW).use { outStream -> - writeAttachmentContentTo(pendingDownload.attachment, outStream) - } + outPath.outputStream(StandardOpenOption.CREATE_NEW).use { outStream -> + writeAttachmentContentTo(pendingDownload.attachment, outStream) + } - logger.info("Finished downloading channel $channelId attachment $number") + logger.info("Finished downloading channel $channelId attachment $number") + } catch (e: Exception) { + logger.error( + "Error downloading channel $channelId attachment $number; name: $fileName; url: ${pendingDownload.attachment.url}", + e, + ) + + attachmentDir.resolve("ERROR.txt").writeText(e.stackTraceToString()) + } } } }