From 61d52cd9db1de4a9fc363b971459d3ba0c23d1e9 Mon Sep 17 00:00:00 2001 From: davotoula Date: Sat, 9 May 2026 17:42:12 +0200 Subject: [PATCH] fix(uploads): surface blurhash/thumbhash generation failures processBitmap silently swallowed any exception from bitmap.toBlurhash() or bitmap.toThumbhash() via runCatching{...}.getOrNull(), making it impossible to diagnose why a video upload's published imeta had blurhash but no thumbhash (or neither). Add an .onFailure { Log.w(...) } to each runCatching so the actual exception class + stack reach logcat. --- .../uploads/PreviewMetadataCalculator.kt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/PreviewMetadataCalculator.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/PreviewMetadataCalculator.kt index 5d8aed97c..c85e13ade 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/PreviewMetadataCalculator.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/PreviewMetadataCalculator.kt @@ -48,6 +48,8 @@ data class PreviewHashes( } object PreviewMetadataCalculator { + private const val LOG_TAG = "PreviewMetadataCalc" + private fun isImage(mimeType: String?) = mimeType?.startsWith("image/", ignoreCase = true) == true private fun isVideo(mimeType: String?) = mimeType?.startsWith("video/", ignoreCase = true) == true @@ -117,7 +119,7 @@ object PreviewMetadataCalculator { } } } catch (e: Exception) { - Log.w("PreviewMetadataCalc", "Failed to compute metadata from uri", e) + Log.w(LOG_TAG, "Failed to compute metadata from uri", e) null } } @@ -133,8 +135,14 @@ object PreviewMetadataCalculator { private fun processBitmap(bitmap: Bitmap?): PreviewHashes = if (bitmap != null) { try { - val blurhash = runCatching { BlurhashWrapper(bitmap.toBlurhash()) }.getOrNull() - val thumbhash = runCatching { ThumbhashWrapper(bitmap.toThumbhash()) }.getOrNull() + val blurhash = + runCatching { BlurhashWrapper(bitmap.toBlurhash()) } + .onFailure { Log.w(LOG_TAG, "blurhash generation failed", it) } + .getOrNull() + val thumbhash = + runCatching { ThumbhashWrapper(bitmap.toThumbhash()) } + .onFailure { Log.w(LOG_TAG, "thumbhash generation failed", it) } + .getOrNull() PreviewHashes( blurhash = blurhash, thumbhash = thumbhash, @@ -153,6 +161,9 @@ object PreviewMetadataCalculator { ): PreviewHashes { val dim = retriever.prepareDimFromVideo() ?: dimPrecomputed val thumb = retriever.getThumbnail() + if (thumb == null) { + Log.w(LOG_TAG) { "video frame extraction returned null; no blurhash/thumbhash will be generated" } + } val hashes = processBitmap(thumb) val finalDim = if (dim?.hasSize() == true) dim else hashes.dim return hashes.copy(dim = finalDim)