-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache SW: Ensure any failure is always logged. #8328
Cache SW: Ensure any failure is always logged. #8328
Conversation
src/service-worker/core.js
Outdated
@@ -624,6 +624,10 @@ export function handleFetch(request, maybeClientId) { | |||
// If not, let's fetch and cache the request. | |||
return fetchJsFile(cache, versionedRequest, pathname, version); | |||
}); | |||
}).catch(err => { | |||
// Throw error out of band. | |||
Promise.reject(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"This throws the error out-of-band with the promise chain." If we didn't do this, the enclosing promise chain would be passed to event.respondWith
, which installs a #catch
block, which means it's rejection is handled. We have to create a new rejected promise that is not handled to get the unhandledrejection
event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this line just create a rejected promise? I thought you'd need to call the throw
async to avoid having the promise swallow the error, e.g. with setTimeout
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's exactly what it does 😉. And because I don't attach a #catch
block to it, its rejection won't ever be handled.
I could have also done a setTimeout
and throw
.
* Ensure any failure is always logged. * lint * Tell closure compiler it'll be alright.
If any failure happens in the promise chain, we want to hear about it. But unfortunately, the
event.respondWith
that we eventually pass the promise to will install a rejection handler, which means we won't get aunhandledrejection
event.This throws the error out-of-band with the promise chain.