New issue
Advanced search Search tips

Issue 769726 link

Starred by 2 users

Issue metadata

Status: WontFix
Owner: ----
Closed: Oct 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: Feature



Sign in to add a comment

Defining new Error classes in WebIDL

Project Member Reported by guidou@chromium.org, Sep 28 2017

Issue description

There 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).


 
Cc: domenic@chromium.org peria@chromium.org
Labels: -Type-Bug Type-Feature
Status: Available (was: Untriaged)
domenic@, what do you think of this issue?
Do we have any plan to extend Web IDL so that it can define subclasses of Error?

Cc: yukishiino@chromium.org
Cc: bashi@chromium.org
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.
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).
Cc: guidou@chromium.org
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.
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?
Status: WontFix (was: Available)

Comment 8 by foolip@chromium.org, 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