I am experimenting with catching Javascript errors with raven.js [1] (see
the JS error logging RfC [2] for background; see T1345 [3] for a prototype
for JS error logging). For various reasons, Javascript does not have a
reliable way to install a global exception handler like e.g. PHP does with
set_exception_handler(), so the standard way of doing this is to wrap
modules into a try-catch block.
ResourceLoader already wraps minified scripts with something like
mw.loader.implement( "<module name>", function() { <module code> }
);
so this could be changed to something like
mw.loader.implement( "<module name>", Raven.wrap( function() { <module
code> } ) );
That means that the error logging module would have to be loaded by the
time other modules are initialized, so I imagine it would have to become a
startup module. My questions are:
1. do you see any problems with such a setup? The eventual goal would be to
use this on the Wikimedia production cluster.
2. especially, is adding another startup script acceptable? (Adding
raven.js to the jquery and mediawiki modules would mean a ~10% size
increase.)
3. what would be the proper way of doing this from an extension? Add two
new hooks for module wrapping and for defining additional startup modules?
[1]
https://github.com/getsentry/raven-js
[2]
https://www.mediawiki.org/wiki/Requests_for_comment/Server-side_Javascript_…
[3]
https://phabricator.wikimedia.org/T1345