Re: [csswg-drafts] [web-animations-1] Should async playback methods return the `ready` Promise?

I wrote the spec text for this and implemented it but then I discovered that if we make the return type of an operation a Promise-type, WebIDL automatically turns exceptions into rejected promises. See [create an operation function](https://heycam.github.io/webidl/#dfn-create-operation-function), step 2, "And then, if an exception E was thrown:" branch, step 1.

That seems unfortunate since it would mean that these methods can no longer return the `ready`/`finished` promises. For example, under normal circumstances if you called `reverse()` on a finished animation we'd return the animation's (possibly updated) _current finished promise_. However, if you called it on an animation that can't be reversed we **don't** want to mutate the animation's _current finished promise_ since a failed call should leave the animation unmodified (strong exception safety). While we can simply return a different rejected Promise in that case it would mean the return value of `reverse()` is no longer strictly equivalent to the _current finished promise_.

Furthermore, if we make this change any existing code relying on exceptions (is there any?) will break, and all callers are effectively forced into using the Promise API--and if they only care about detecting exceptional circumstances they need to write code to distinguish between cancellation and failure cases.

e.g.

```js
// I really only care if the following call passes or not
anim.reverse().catch(err => {
  // If the animation was canceled at some unspecified time later, I don't care.
  if (typeof err.name === 'string' && err.name === 'AbortError') {
    return;
  }
  // I do care about other errors though.
  throw err;
});
```

I'm a bit stuck as to what we should do here.

-- 
GitHub Notification of comment by birtles
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/2206#issuecomment-366154744 using your GitHub account

Received on Friday, 16 February 2018 06:28:05 UTC