馃悰 [Story animation] Fix error thrown when user pauses before animation runs. #35161
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes ampproject/error-reporting#94
When the story animations are not initialized (eg: because the story page is not visible yet, due to prerender mode), calling
pause
will throw an error becausethis.players_ == null
.There was a try/catch that was catching this error that was removed in #34466 that is needed.
https://github.com/ampproject/amphtml/pull/34466/files#diff-c5a86c80a77ae2a9abb4ac5ff1e9ef10f58c0e9262baa64273be1b4424d7161bL383-L388
We can re-introduce this try-catch and prevent these errors from surfacing, which is ok since the story is not initialized when the pause method is called. Changing the comment to more clearly explain why the method call can fail
An alternative is to change the behavior of pause by doing
if (!this.players_) {return;}
(silently fail the pause) but it will alter the API. Another alternative is to call init before calling pause but it would be extra work for initializing the animations when users pause the story, which could introduce delays in the rest of the pausing code.