Defining new Error classes in WebIDL |
|||||
Issue descriptionThere is apparently no easy way to define new Error classes in WebIDL and this is needed in some cases. For example, the MediaStreams spec requires defining OverconstrainedError as a class derived from Error (see https://w3c.github.io/mediacapture-main/#error-handling).
,
Oct 6 2017
,
Oct 6 2017
We've talked about this a bit over email together with bashi@ a while ago, but it wasn't clear to me if this was the direction we really wanted to go.
,
Oct 6 2017
Let me copy the gist of my reply from that email thread, since it's better having a public record. OverconstrainedError is not possible to define in Web IDL, and requires custom bindings. This is by design; the spec does not use IDL, and so neither would our implementation. If we were to try to add IDL-defined custom errors at the spec level, we probably wouldn't do it like OverconstrainedError. One solution we've thrown around is extending DOMException with some kind of options object that allows arbitrary extra data. It's unclear how this would work exactly, but then you could just use DOMException and not define a new error type. If that's increasingly urgent, let me know. However that might not be the right path for OverconstrainedError in particular, if other browsers are already shipping the current spec. In case it helps, here is a completely spec-compliant implementation of OverconstrainedError in V8 extras (https://bit.ly/v8-extras): https://gist.github.com/domenic/a4c438614eebd0f04679ee222a884948 (although untested).
,
Oct 6 2017
For OverconstrainedError we chose to use an interface at the moment, similar to the current definition of DOMException. Thanks for the V8 extras implementation. We initially went with interface for simplicity. I have to read the document to learn how to use it from C++. It might be exactly what we need.
,
Oct 13 2017
Okay, I've not deeply dug into this, however it seems like that "Media Capture and Streams" spec unnecessarily made error reporting complicated (IMHO). And we wouldn't like to support it. Shall we close this issue as WontFix?
,
Oct 20 2017
,
Jan 21
(2 days ago)
There's an additional case now, RTCError, which is about to ship: https://groups.google.com/a/chromium.org/d/msg/blink-dev/TsJA1XX7mTE/nlQ0FFjSDgAJ domenic@, yukishiino@, would you mind taking a look at that to see if it suggests a need to be able to define these things using Web IDL? |
|||||
►
Sign in to add a comment |
|||||
Comment 1 by yukishiino@chromium.org
, Oct 6 2017Labels: -Type-Bug Type-Feature
Status: Available (was: Untriaged)