Skip to content

Commit 84d807b

Browse files
committed
fix(cache): handle cache removal errors gracefully
Wrap cacache.remove() calls in try/catch to prevent crashes when: - Entry doesn't exist in persistent cache - Cache directory is inaccessible (e.g., during test setup) - File system permissions issues
1 parent cb62e6f commit 84d807b

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/cache-with-ttl.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,12 @@ export function createTtlCache(options?: TtlCacheOptions): TtlCache {
263263
return entry.data
264264
}
265265
// Remove expired entry.
266-
await cacache.remove(fullKey)
266+
try {
267+
await cacache.remove(fullKey)
268+
} catch {
269+
// Ignore removal errors - entry may not exist in persistent cache
270+
// or cache directory may not be accessible (e.g., during test setup).
271+
}
267272
}
268273

269274
return undefined
@@ -446,7 +451,11 @@ export function createTtlCache(options?: TtlCacheOptions): TtlCache {
446451

447452
const fullKey = buildKey(key)
448453
memoCache.delete(fullKey)
449-
await cacache.remove(fullKey)
454+
try {
455+
await cacache.remove(fullKey)
456+
} catch {
457+
// Ignore removal errors - entry may not exist or cache may be inaccessible.
458+
}
450459
}
451460

452461
/**

0 commit comments

Comments
 (0)