JS XPCOM and error reporting (Bug 1044109 )

R Kent James kent at caspia.com
Thu Jun 23 17:48:23 UTC 2016


Since as a general tendency mailnews code is moving toward JS XPCOM
versions of our code, I'd like to point out a gotcha to be careful of,
which might also affect C++ designs.

Recently bug 1044109 was WONTFIXED. What that means is that when a JS
XPCOM component throws an exception, that always shows up as an error in
the error console, even if the caller wraps the error in a try/catch block.

Some of our C++ code makes use of passing status information routinely
in the rv value. What that maps to in JS XPCOM is:

  throw CE("the error description", Cr.NS_ERROR_whatever);

Unfortunately this construction when part of a JS XPCOM component now
will always show on the error console. This has been true for a couple
of years now, but we have not really thought about it.

This has a big impact on JsAccount which is currently landing, as that
results in a typical architecture of adapting C++ XPCOM components to JS
XPCOM. If the C++ component routinely returns error values of rv,
assuming that those will then be handled cleanly by callers, that does
not map well to JS world. Please avoid this architecture, and expect to
see some patches that remove cases where we do this. Throws in JS should
be reserved for cases where they are considered unexpected or otherwise
require developer attention.

I'm not really happy about this, as JS exceptions can be useful. Are
there reasonable alternatives here?

:rkent



More information about the tb-planning mailing list