Hello all,

I just checked in some improvements to how we report exceptions on ErrorResult and in promise rejections [1]. Summary:

1) The public ThrowDOMException method that takes an nsresult and a string is gone. Instead, there are methods like ThrowIndexSizeError, ThrowHierarchyRequestError, etc, matching the error names defined at <https://heycam.github.io/webidl/#idl-DOMException-error-names>. So whenever the spec says to "throw an SecurityError exception" or whatnot, you call ThrowSecurityError. These methods can take either a string literal ("foo") or any nsACString. nsPrintfCString can be used to produce error messages that depend on the input to the DOM method.

2) The public Promise::MaybeRejectWithDOMException method is gone. Instead there are MaybeRejectWithIndexSizeError, etc, methods. Again, these just take the string to use for the message as input.

3) While ErrorResult::Throw taking just an nsresult still exists, it is deprecated and new code should not be adding new calls to it if that can be avoided. Callsites that pass a constant nsresult value can be changed to use the above methods with meaningful error messages; I will be doing some of that, but would appreciate help from subject matter experts who can probably write better error messages than I can. Same thing for ErrorResult::operator=(nsresult).

4) Promise::MaybeReject(nsresult) still exists, but is deprecated. Please try to convert to one of the above methods or taking an ErrorResult that had a meaningful exception thrown on it.

I would really like to get to the point where when web developers see errors in their console they don't have to guess what caused those errors, and having meaningful messages is the simplest way to get there.

-Boris

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1612213
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to