-
Notifications
You must be signed in to change notification settings - Fork 165
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
What to do about specs that need lots of error types #1219
Comments
I tend to see it as only two levels, name and responseCode. At least without cross-global instanceof you wouldn't want to rely on that. I guess it depends a bit on the exact use cases and how developers are expected to deal with it. Also, do they need to branch on things besides smartcode-specific exceptions, e.g., "SyntaxError" or "InvalidStateError"? |
Also be clearer about how exception names are meant to be used, at least for now (pending discussion in #1219). See discussion in #1168 (comment). Closes #1223. This also includes some updates to all exception creation and throwing, such as reflecting how messages are actually passed along in practice, or using Web IDL infrastructure to create DOMException instances instead of Construct()ing them.
Also be clearer about how exception names are meant to be used, at least for now (pending discussion in #1219). See discussion in #1168 (comment). Closes #1223. This also includes some updates to all exception creation and throwing, such as reflecting how messages are actually passed along in practice, or using Web IDL infrastructure to create DOMException instances instead of Construct()ing them.
The first level is reliable cross-realm using
@dandrader knows the specific case better, but I could easily imagine some sort of "get me a smartcard" API which can fail with:
Similar patterns can be seen with the Web Serial case, where I am pretty sure @reillyeon added the separate errors because developers are expected to take different actions depending on them. And #1168 indicates a desire to distinguish two different types of aborts, one where the user presses "Cancel" and one where the user opts out of the process (which is, somehow, different?). |
Right, but in that case isn't a single exception type for all SmartCard stuff kinda nice? At least it seems likely you might have shared logic there whereas you wouldn't necessarily with the other two exceptions. |
But when you don't have shared error handling logic among all errors of a given specialised error class then this two-layered approach is a hindrance instead of an asset. The benefit I see in having a specialised error class is not polluting the DOMException.name namespace, at the cost of a more complex error type (with inheritance and two members, "name" and "responseCode"), which inevitably leads into a two-layered error handling logic (again, more complexity). That assuming this "namespace pollution" is a problem in the first place. If all smartcard-specific errors were also represented via specific DOMException.name values, one could for instance have a single map from DOMException.name value to error handling function. And that also wouldn't impede one from sharing code between error cases when appropriate. This looks better to me. |
Also be clearer about how exception names are meant to be used, at least for now (pending discussion in #1219). See discussion in #1168 (comment). Closes #1223. This also includes some updates to all exception creation and throwing, such as reflecting how messages are actually passed along in practice, or using Web IDL infrastructure to create DOMException instances instead of Construct()ing them.
Also be clearer about how exception names are meant to be used, at least for now (pending discussion in #1219). See discussion in #1168 (comment). Closes #1223. This also includes some updates to all exception creation and throwing, such as reflecting how messages are actually passed along in practice, or using Web IDL infrastructure to create DOMException instances instead of Construct()ing them.
Also be clearer about how exception names are meant to be used, at least for now (pending discussion in #1219). See discussion in #1168 (comment). Closes #1223. This also includes some updates to all exception creation and throwing, such as reflecting how messages are actually passed along in practice, or using Web IDL infrastructure to create DOMException instances instead of Construct()ing them.
Also be clearer about how exception names are meant to be used, at least for now (pending discussion in #1219). See discussion in #1168 (comment). Closes #1223. This also includes some updates to all exception creation and throwing, such as reflecting how messages are actually passed along in practice, or using Web IDL infrastructure to create DOMException instances instead of Construct()ing them.
Spinning this off from #1211 since I think it deserves its own discussion:
@dandrader made me aware that the case he's working on is unlike
RTCError
orWebTransportError
(or the pull request'sWidgetError
) in that he basically just needs more error types.Specifically, his case is a smart card API, which has ~15 different SmartCard-specific error codes. (It seems like the plan is to expose a subset of these to the web.)
I see several routes we could go for this sort of API:
SmartCodeError
, with a separateresponseCode
property which is one of the ~15 values.SCARD_E_NO_SMARTCARD
, or "NotAllowedError" forSCARD_E_SHARING_VIOLATION
.)At first I was pushing for (1), but now I'm thinking one of the other options might be better. Especially since it's weird for an error to have three subtypes:
DOMException
>name = "SmartCardError"
>responseCode = "not-ready"
seems a bit excessive, compared to idiomatic JavaScript errors which just have one level (TypeError
,SyntaxError
, etc.).Some prior art:
What do others think? I guess the main questions are: (a) should
DOMException
'sname
be reserved for generic broad categories, or is it OK to allow spec-specific error names; and (b) if we do allow spec-specific error names, should Web IDL's error names table act as a coordination point, or should we just let specs do what they want?The text was updated successfully, but these errors were encountered: