« get me outta code hell

thumbs: be more careful with invalid cache entries - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-01-30 13:39:35 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-30 13:39:35 -0400
commit0ff3e151785a6bc016c29973c38a773efc4a7ce1 (patch)
treede7d111928db70579171168a389664d937422126 /src
parent4aca33098a53d29082e1e121d841d5eb6fb07126 (diff)
thumbs: be more careful with invalid cache entries
Diffstat (limited to 'src')
-rw-r--r--src/gen-thumbs.js20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/gen-thumbs.js b/src/gen-thumbs.js
index f0eb72a0..cecedc82 100644
--- a/src/gen-thumbs.js
+++ b/src/gen-thumbs.js
@@ -397,7 +397,18 @@ export function getDimensionsOfImagePath(mediaPath, cache) {
     throw new Error(`Expected mediaPath to be included in cache, got ${mediaPath}`);
   }
 
-  const {width, height} = thumbnailCacheEntryToDetails(cacheEntry);
+  const details = thumbnailCacheEntryToDetails(cacheEntry);
+
+  if (!details) {
+    throw new Error(`Couldn't determine any details for this image (${mediaPath})`);
+  }
+
+  const {width, height} = details;
+
+  if (typeof width !== 'number' && typeof height !== 'number') {
+    throw new Error(`Details for this image don't appear to contain dimensions (${mediaPath})`);
+  }
+
   return [width, height];
 }
 
@@ -792,6 +803,13 @@ export async function refreshThumbnailCache(cache, {mediaPath, queueSize}) {
         .map(([imagePath, cacheEntry]) => async () => {
           const details = thumbnailCacheEntryToDetails(cacheEntry);
 
+          // Couldn't parse this entry, it won't be used later on.
+          // But leave it around just in case some other version of hsmusic
+          // can get use out of it.
+          if (!details) {
+            return;
+          }
+
           const {tackbust, width, height} = details;
 
           let {md5, mtime} = details;