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:
+14
-3
@@ -48,6 +48,8 @@ data class PreviewHashes(
|
|||||||
}
|
}
|
||||||
|
|
||||||
object PreviewMetadataCalculator {
|
object PreviewMetadataCalculator {
|
||||||
|
private const val LOG_TAG = "PreviewMetadataCalc"
|
||||||
|
|
||||||
private fun isImage(mimeType: String?) = mimeType?.startsWith("image/", ignoreCase = true) == true
|
private fun isImage(mimeType: String?) = mimeType?.startsWith("image/", ignoreCase = true) == true
|
||||||
|
|
||||||
private fun isVideo(mimeType: String?) = mimeType?.startsWith("video/", ignoreCase = true) == true
|
private fun isVideo(mimeType: String?) = mimeType?.startsWith("video/", ignoreCase = true) == true
|
||||||
@@ -117,7 +119,7 @@ object PreviewMetadataCalculator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} 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
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,8 +135,14 @@ object PreviewMetadataCalculator {
|
|||||||
private fun processBitmap(bitmap: Bitmap?): PreviewHashes =
|
private fun processBitmap(bitmap: Bitmap?): PreviewHashes =
|
||||||
if (bitmap != null) {
|
if (bitmap != null) {
|
||||||
try {
|
try {
|
||||||
val blurhash = runCatching { BlurhashWrapper(bitmap.toBlurhash()) }.getOrNull()
|
val blurhash =
|
||||||
val thumbhash = runCatching { ThumbhashWrapper(bitmap.toThumbhash()) }.getOrNull()
|
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(
|
PreviewHashes(
|
||||||
blurhash = blurhash,
|
blurhash = blurhash,
|
||||||
thumbhash = thumbhash,
|
thumbhash = thumbhash,
|
||||||
@@ -153,6 +161,9 @@ object PreviewMetadataCalculator {
|
|||||||
): PreviewHashes {
|
): PreviewHashes {
|
||||||
val dim = retriever.prepareDimFromVideo() ?: dimPrecomputed
|
val dim = retriever.prepareDimFromVideo() ?: dimPrecomputed
|
||||||
val thumb = retriever.getThumbnail()
|
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 hashes = processBitmap(thumb)
|
||||||
val finalDim = if (dim?.hasSize() == true) dim else hashes.dim
|
val finalDim = if (dim?.hasSize() == true) dim else hashes.dim
|
||||||
return hashes.copy(dim = finalDim)
|
return hashes.copy(dim = finalDim)
|
||||||
|
|||||||
Reference in New Issue
Block a user