-
Notifications
You must be signed in to change notification settings - Fork 7
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
Only use exceptions/promise rejections for exceptional situations #5
Comments
If I understand correctly, you would recommend that |
Yeah, that sounds right to me, assuming it is exceptional for there to be no metadata. |
Not having metadata isn't rare, it just depends how the media element is setup. The idea here is that the call would require this (as a "contract") and not being in this state would fail. I believe it's something that other HTML elements do such as HTMLInputElement that throws when some properties are used when not set to a certain type. |
Oh, no, in that case, I would suggest a tri-state return value, e.g. "unknown", "yes", "no" or similar. We did used to have some input element stuff about selection that would throw when used in the wrong state, but that violated this design principle and so we changed it to return null. whatwg/html#1006 and whatwg/html#2327 |
I think a tri-state would make things harder. It was our initial idea but it's very easy to do the wrong thing when using a real tri-state (not a DOMString?) as the third state will either have to be designed to look like Though, I would like to discuss this "design principle". Design by contract is a fairly common software pattern design and this really helps in this situation. I think this is really the best solution for our problem here. Furthermore, we already have many promises throwing that are not exceptional cases. For example, |
Related to #3, but seems separate. You should not throw an exception, or analogously return a rejected promise, in mainline scenarios. Instead you should provide a non-throwing/rejecting function which returns a sync value or fulfilled promise explaining how to avoid the error cases.
In particular, something named "play()" could return a rejection if playing cannot happen. But something named "canAutoplay()" should only return a boolean; it should never throw/reject. (Except perhaps in cases of weird hardware failure??)
The text was updated successfully, but these errors were encountered: