From 0ff3e151785a6bc016c29973c38a773efc4a7ce1 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 30 Jan 2024 13:39:35 -0400 Subject: thumbs: be more careful with invalid cache entries --- src/gen-thumbs.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src') 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; -- cgit 1.3.0-6-gf8a5