Skip to content

Commit

Permalink
fix(cache): catch error when getting cache entry (#2609)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjpearson committed Oct 29, 2024
1 parent e3a2d6f commit 6635f79
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/runtime/internal/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ export function defineCachedFunction<T, ArgsT extends unknown[] = any[]>(
.replace(/:\/$/, ":index");

let entry: CacheEntry<T> =
((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") {
Expand Down

0 comments on commit 6635f79

Please sign in to comment.