If a native javascript method fails (eg. calling a member as a function on a non-object) there's an error thrown:
TypeError: Result of expression 'f.test' [undefined] is not a function. [test.js:2]
But when a custom error is thrown (ie. "MediaWiki DeprecatedWarning: Function mw.legacy.sajax_init_object is deprecated" ) it will report no file/line number to the console or in some cases the filename and line number where the throw originates from, not where the function was called.
So the goal of this bug is to end up with something like:
- short wrappers to avoid doing any throws directly in the code (would use or do something like jQuery.error )
- mw.log (what it is now, simple dummy in production and console.log or mw.console in debug for logging messages)
- mw.log.error and mw.log.warning for throwing stuff
- mw.log.deprecated calls mw.log.warning with some magic stuff to know what was called and where it comes from
- example of where it is defined
mw.legacy.sajax_init_object : function() {
mw.log.deprecated();
/* stuff */
}
- example of where it would be triggered
function myGadget(){
var path = '...'; var xhttp = mw.legacy.sajax_init_object() /* etc. stuff */ var foobar = getStuff(); mw.util.addPortletLink( foobar );
}
- example of console output
{X} MWDeprecatedWarning: Use of sajax_init_object is deprecated [mygadget.js:3]
{X} MWSyntaxError: addPortletLink requires at least 3 arguments, 2 given [mygadget:49]
Links of interest:
- https://github.com/emwendelin/javascript-stacktrace/blob/master/stacktrace.js
- http://eriwen.com/javascript/stacktrace-update/
Krinkle
Version: 1.17.x
Severity: enhancement