From 6635f79761ee0c19f1daf043e9f94fe50ac5fa43 Mon Sep 17 00:00:00 2001 From: Connor Pearson Date: Tue, 29 Oct 2024 21:53:58 +0100 Subject: [PATCH] fix(cache): catch error when getting cache entry (#2609) --- src/runtime/internal/cache.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/runtime/internal/cache.ts b/src/runtime/internal/cache.ts index 56b4251d41..72747fe1fe 100644 --- a/src/runtime/internal/cache.ts +++ b/src/runtime/internal/cache.ts @@ -57,7 +57,12 @@ export function defineCachedFunction( .replace(/:\/$/, ":index"); let entry: CacheEntry = - ((await useStorage().getItem(cacheKey)) as unknown) || {}; + ((await useStorage() + .getItem(cacheKey) + .catch((error) => { + console.error(`[nitro] [cache] Cache read error.`, error); + useNitroApp().captureError(error, { event, tags: ["cache"] }); + })) as unknown) || {}; // https://github.com/unjs/nitro/issues/2160 if (typeof entry !== "object") {