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.
This commit is contained in:
davotoula
2026-05-09 17:42:12 +02:00
parent fb7a30fd70
commit 61d52cd9db
@@ -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)