Browse Source

fix unhandled runtime error, and ignore doesn't exist error

Abhinav 1 year ago
parent
commit
0dd6dadd12
1 changed files with 8 additions and 2 deletions
  1. 8 2
      src/services/diskCache.ts

+ 8 - 2
src/services/diskCache.ts

@@ -35,7 +35,10 @@ export class DiskCache implements LimitedCache {
                     Error(),
                     Error(),
                     'Cache key exists but size does not match. Deleting cache key.'
                     'Cache key exists but size does not match. Deleting cache key.'
                 );
                 );
-                unlink(cachePath);
+                unlink(cachePath).catch((e) => {
+                    if (e.code === 'ENOENT') return;
+                    logError(e, 'Failed to delete cache key');
+                });
                 return undefined;
                 return undefined;
             }
             }
             DiskLRUService.touch(cachePath);
             DiskLRUService.touch(cachePath);
@@ -53,7 +56,10 @@ export class DiskCache implements LimitedCache {
                         Error(),
                         Error(),
                         'Old cache key exists but size does not match. Deleting cache key.'
                         'Old cache key exists but size does not match. Deleting cache key.'
                     );
                     );
-                    unlink(oldCachePath);
+                    unlink(oldCachePath).catch((e) => {
+                        if (e.code === 'ENOENT') return;
+                        logError(e, 'Failed to delete cache key');
+                    });
                     return undefined;
                     return undefined;
                 }
                 }
                 const match = new Response(await getFileStream(oldCachePath));
                 const match = new Response(await getFileStream(oldCachePath));