Improve logging when falling back to transit tier for attachment downloads

This commit is contained in:
trevor-signal
2025-05-16 12:17:01 -04:00
committed by GitHub
parent fca742b37b
commit e37c95bddf
2 changed files with 14 additions and 3 deletions

View File

@@ -751,7 +751,7 @@ export async function runDownloadAttachmentJobInner({
!preferBackupThumbnail
) {
log.error(
`${logId}: failed to download fullsize attachment, falling back to thumbnail`,
`${logId}: failed to download fullsize attachment, falling back to backup thumbnail`,
Errors.toLogFormat(error)
);
try {

View File

@@ -90,18 +90,29 @@ export async function downloadAttachment({
}
);
} catch (error) {
const shouldFallbackToTransitTier =
variant !== AttachmentVariant.ThumbnailFromBackup;
if (error instanceof HTTPError && error.code === 404) {
// This is an expected occurrence if restoring from a backup before the
// attachment has been moved to the backup tier
log.warn(`${logId}: attachment not found on backup CDN`);
log.warn(
`${logId}: attachment not found on backup CDN`,
shouldFallbackToTransitTier ? 'will try transit tier' : ''
);
} else {
// We also just log this error instead of throwing, since we want to still try to
// find it on the attachment tier.
log.error(
`${logId}: error when downloading from backup CDN; will try transit tier`,
`${logId}: error when downloading from backup CDN`,
shouldFallbackToTransitTier ? 'will try transit tier' : '',
toLogFormat(error)
);
}
if (!shouldFallbackToTransitTier) {
throw error;
}
}
}