{"record":{"id":"928857924d0d4609","repo":"angular/angular","slug":"failed-to-update-the-caches-for-request-to-req","errorCode":null,"errorMessage":"Failed to update the caches for request to '${req.url}' (fetchAndCacheOnce): ${errorToString(err)}","messagePattern":"Failed to update the caches for request to '(.+?)' \\(fetchAndCacheOnce\\): (.+?)","errorType":"exception","errorClass":"SwCriticalError","httpStatus":null,"severity":"error","filePath":"packages/service-worker/worker/src/assets.ts","lineNumber":353,"sourceCode":"        const cache = await this.cache;\n        await cache.put(req, res.clone());\n\n        // If the request is not hashed, update its metadata, especially the timestamp. This is\n        // needed for future determination of whether this cached response is stale or not.\n        if (!this.hashes.has(this.adapter.normalizeUrl(req.url))) {\n          // Metadata is tracked for requests that are unhashed.\n          const meta: UrlMetadata = {ts: this.adapter.time, used};\n          const metaTable = await this.metadata;\n          await metaTable.write(req.url, meta);\n        }\n\n        return res;\n      } catch (err) {\n        // Among other cases, this can happen when the user clears all data through the DevTools,\n        // but the SW is still running and serving another tab. In that case, trying to write to the\n        // caches throws an `Entry was not found` error.\n        // If this happens the SW can no longer work correctly. This situation is unrecoverable.\n        throw new SwCriticalError(\n          `Failed to update the caches for request to '${\n            req.url\n          }' (fetchAndCacheOnce): ${errorToString(err)}`,\n        );\n      }\n    } finally {\n      // Finally, it can be removed from `inFlightRequests`. This might result in a double-remove\n      // if some other chain was already making this request too, but that won't hurt anything.\n      this.inFlightRequests.delete(req.url);\n    }\n  }\n\n  protected async fetchFromNetwork(req: Request, redirectLimit: number = 3): Promise<Response> {\n    // Make a cache-busted request for the resource.\n    const res = await this.cacheBustedFetchFromNetwork(req);\n\n    // Check for redirected responses, and follow the redirects.\n    if ((res as any)['redirected'] && !!res.url) {","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/angular/angular/blob/51cb07e98081ab7e4e84a9e0949266a8e19cca84/packages/service-worker/worker/src/assets.ts#L335-L371","documentation":"After a successful fetch, the service worker writes the response into CacheStorage and its metadata into IndexedDB; if that write throws — the code comment cites 'Entry was not found' when the user cleared all data via DevTools while the SW was still running and serving another tab — the SW can no longer work correctly and throws SwCriticalError (the situation is unrecoverable for that SW instance). The Driver falls back to a safe network fetch for the current request.","triggerScenarios":"cache.put() or the metadata-table write rejecting inside fetchAndCacheOnce: site data cleared while the SW stays alive in another tab, storage eviction under quota pressure, or browser storage corruption.","commonSituations":"'Clear site data' clicked in DevTools with the PWA open in another window/tab; iOS/Safari aggressive storage eviction; low-disk devices where the browser revokes storage.","solutions":["Unregister the service worker and reload to force a clean install: navigator.serviceWorker.getRegistrations().then(rs => rs.forEach(r => r.unregister())).","When clearing storage intentionally, close all app tabs first so no SW survives to observe the wipe.","Ship a new app version so existing clients pick up a fresh SW with rebuilt caches."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["When clearing site data intentionally, close all tabs of the app first so no service worker survives the wipe.","Provide an in-app recovery path (unregister SW + reload) for users who report offline breakage after clearing data.","Ship new app versions periodically so stale/broken SW instances get replaced."],"tags":["service-worker","cache-storage","sw-critical-error","storage"],"backgroundTag":"cache-storage-error","analyzedSha":"51cb07e98081ab7e4e84a9e0949266a8e19cca84","analyzedAt":"2026-08-22T07:04:54.531Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}