@@ -128,7 +128,17 @@ export abstract class AssetGroup {
128128
129129 // Look for a cached response. If one exists, it can be used to resolve the fetch
130130 // operation.
131- const cachedResponse = await cache . match ( req , this . config . cacheQueryOptions ) ;
131+ let cachedResponse : Response | undefined ;
132+ try {
133+ // Safari 16.4/17 is known to sometimes throw an unexpected internal error on cache access
134+ // This try/catch is here as a workaround to prevent a failure of the handleFetch
135+ // as the Driver falls back to safeFetch on critical errors.
136+ // See #50378
137+ cachedResponse = await cache . match ( req , this . config . cacheQueryOptions ) ;
138+ } catch ( error ) {
139+ throw new SwCriticalError ( `Cache is throwing while looking for a match: ${ error } ` ) ;
140+ }
141+
132142 if ( cachedResponse !== undefined ) {
133143 // A response has already been cached (which presumably matches the hash for this
134144 // resource). Check whether it's safe to serve this resource from cache.
@@ -529,8 +539,19 @@ export class PrefetchAssetGroup extends AssetGroup {
529539 // Construct the Request for this url.
530540 const req = this . adapter . newRequest ( url ) ;
531541
532- // First, check the cache to see if there is already a copy of this resource.
533- const alreadyCached = ( await cache . match ( req , this . config . cacheQueryOptions ) ) !== undefined ;
542+ let alreadyCached = false ;
543+ try {
544+ // Safari 16.4/17 is known to sometimes throw an unexpected internal error on cache access
545+ // This try/catch is here as a workaround to prevent a failure of the handleFetch
546+ // as the Driver falls back to safeFetch on critical errors.
547+ // See #50378
548+
549+ // First, check the cache to see if there is already a copy of this resource.
550+ alreadyCached = ( await cache . match ( req , this . config . cacheQueryOptions ) ) !== undefined ;
551+ } catch ( error ) {
552+ throw new SwCriticalError (
553+ `Cache is throwing while looking for a match in a PrefetchAssetGroup: ${ error } ` ) ;
554+ }
534555
535556 // If the resource is in the cache already, it can be skipped.
536557 if ( alreadyCached ) {
@@ -607,8 +628,19 @@ export class LazyAssetGroup extends AssetGroup {
607628 // Construct the Request for this url.
608629 const req = this . adapter . newRequest ( url ) ;
609630
610- // First, check the cache to see if there is already a copy of this resource.
611- const alreadyCached = ( await cache . match ( req , this . config . cacheQueryOptions ) ) !== undefined ;
631+ let alreadyCached = false ;
632+ try {
633+ // Safari 16.4/17 is known to sometimes throw an unexpected internal error on cache access
634+ // This try/catch is here as a workaround to prevent a failure of the handleFetch
635+ // as the Driver falls back to safeFetch on critical errors.
636+ // See #50378
637+
638+ // First, check the cache to see if there is already a copy of this resource.
639+ alreadyCached = ( await cache . match ( req , this . config . cacheQueryOptions ) ) !== undefined ;
640+ } catch ( error ) {
641+ throw new SwCriticalError (
642+ `Cache is throwing while looking for a match in a LazyAssetGroup: ${ error } ` ) ;
643+ }
612644
613645 // If the resource is in the cache already, it can be skipped.
614646 if ( alreadyCached ) {
0 commit comments