Skip to content
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

Merged
merged 3 commits into from
Mar 22, 2017

Conversation

jridgewell
Copy link
Contributor

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 a unhandledrejection event.

This throws the error out-of-band with the promise chain.

@jridgewell jridgewell changed the title Ensure any failure is always logged. Cache SW: Ensure any failure is always logged. Mar 22, 2017
@@ -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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line necessary?

Copy link
Contributor Author

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.

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.

Copy link
Contributor Author

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.

@jridgewell jridgewell merged commit bce0034 into ampproject:master Mar 22, 2017
@jridgewell jridgewell deleted the cache-sw-diversions-6 branch March 22, 2017 23:23
mrjoro pushed a commit to mrjoro/amphtml that referenced this pull request Apr 28, 2017
* Ensure any failure is always logged.

* lint

* Tell closure compiler it'll be alright.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants