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

[web-animations-1] Fix invalid error code for KeyfameEffect.pseudoElement #4829

Merged
merged 2 commits into from
Mar 9, 2020

Conversation

george-steel
Copy link
Contributor

Since TypeError is not a valid DOMException error name, change it to SyntaxError (the code for this kind of type error).

@george-steel
Copy link
Contributor Author

@stephenmcgruer

@stephenmcgruer stephenmcgruer changed the title [wen-animations-1] Fix invalid error code for KeyfameEffect.pseudoElement [web-animations-1] Fix invalid error code for KeyfameEffect.pseudoElement Mar 4, 2020
@stephenmcgruer
Copy link
Contributor

I'm OOO currently; can one of the other editors take a look please?

@birtles
Copy link
Contributor

birtles commented Mar 4, 2020

I'm not sure. I think we're trying to match WebIDL semantics here which throws a JS TypeError for an invalid enum value, for example.

@george-steel
Copy link
Contributor Author

There's definitely a case for a JS TypeError. Are there any other examples of it being used for an invalid value outside an infinite family of strings (SyntaxError seems to be used here a lot), or just for values outside finite enums? pseudoElement can take any syntactically valid pseudo-element selector (such as ::foo) whether the selector is supported or not.

@birtles
Copy link
Contributor

birtles commented Mar 4, 2020

There's definitely a case for a JS TypeError. Are there any other examples of it being used for an invalid value outside an infinite family of strings (SyntaxError seems to be used here a lot), or just for values outside finite enums? pseudoElement can take any syntactically valid pseudo-element selector (such as ::foo) whether the selector is supported or not.

One example is that in the process a keyframes argument procedure right towards the end we have:

If parsing the “easing” property fails, throw a TypeError and abort this procedure.

So at least within Web Animations, we currently always use a TypeError. I don't recall exactly how we ended up there. There was certainly at least one case where we were deciding between SyntaxError or TypeError and the advice we got was something along the lines of, "We normally use TypeError, but it doesn't really matter". Maybe @heycam recalls?

@george-steel
Copy link
Contributor Author

To me it seems like either will work. When i asked @stephenmcgruer, he referenced me to the DOMException part fo the WebIDL spec defining

"SyntaxError" DOMException is used to report parsing errors in web APIs, for example when parsing selectors. … The string did not match the expected pattern.

@birtles
Copy link
Contributor

birtles commented Mar 4, 2020

Oh, that seems pretty clear then!

@birtles
Copy link
Contributor

birtles commented Mar 4, 2020

That makes me think we should update the parsing of easing to throw a SyntaxError too. Mind fixing that too?

@stephenmcgruer
Copy link
Contributor

That makes me think we should update the parsing of easing to throw a SyntaxError too. Mind fixing that too?

There is the potential for web compat issues there (slight since its still an exception, but technically authors could be catching TypeErrors specifically currently), right? I think it's probably still reasonable, but just something to think about.

@birtles
Copy link
Contributor

birtles commented Mar 5, 2020

There is the potential for web compat issues there

Yes, that's right. I might be being a bit optimistic that no-one is watching specifically for TypeErrors from those procedures.

@george-steel
Copy link
Contributor Author

It looks looks there are a lot more places (including all of keyframe parsing) besides parsing easing that uses TypeError for infinite families of values instead of the more specific DOMException error types (SyntaxError, RangeError, etc). I now think that this should make the error for pseudo-element selectors a TypeError for consistency and that changing them to the more specific codes should be for another issue.

@george-steel
Copy link
Contributor Author

@birtles @stephenmcgruer what do you think?

@birtles
Copy link
Contributor

birtles commented Mar 5, 2020

I had a quick skim through the spec yesterday and the only two places where I thought SyntaxError would make sense were pseudoElement and easing (although the easing case appears in about 4~5 different places). Many of the others were more enum-like cases where a TypeError seems to match WebIDL best.

Regarding RangeError, I think there's an explicit note in the spec about why we don't use that for at least one case (since if [EnforceRange] is ever able to handle that case, it will throw a TypeError).

So I would be happy with making pseudoElement throw a SyntaxError and then filing a second issue to make easing throw a SyntaxError if we think Web compat won't be a problem.

But all in all, I don't mind too much either way.

@george-steel
Copy link
Contributor Author

Sounds good to me. Patch is ready on my end.

@birtles birtles merged commit 5147190 into w3c:master Mar 9, 2020
@george-steel george-steel deleted the pseudo-syntax-error branch March 10, 2020 17:41
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Mar 10, 2020
Update web-animations WPT tests to incorporate the error handling fix
w3c/csswg-drafts#4829
Clean-up incorrect test cases which matched neither the old or new
error handling procedures.

Make KeyFrameEffect() reject the empty string as a pseudo-selector
as in the spec.

Delete two tests checking CSSPseudoElement identity (since we now return
strings instead) and replace with a tect checking the returned string
against a literal. These should have been removed in
https://chromium-review.googlesource.com/c/chromium/src/+/1894477
but were overlooked.

Change-Id: I5e9edc498bf3dad68ae683cd466ad41554cf10e4
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.

3 participants