Last modified: 2011-11-10 12:32:52 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T20039, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 18039 - onload hook handling shouldn't break when one hook fails
onload hook handling shouldn't break when one hook fails
Status: RESOLVED WORKSFORME
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
1.15.x
All All
: Low normal (vote)
: ---
Assigned To: Nobody - You can work on this!
http://commons.wikimedia.org/w/index....
: javascript, patch, patch-need-review
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-03-18 19:30 UTC by Mike.lifeguard
Modified: 2011-11-10 12:32 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Patch to wikibits.js for bug 18039 (3.65 KB, patch)
2009-03-18 21:44 UTC, Lupo
Details

Description Mike.lifeguard 2009-03-18 19:30:51 UTC
Copied from http://commons.wikimedia.org/w/index.php?title=Commons:Administrators%27_noticeboard&oldid=19396943#Javascript:

Our current setup with Javascripts has the problem that errors in one script may prevent other scripts from working. Most of our scripts (gadgets and others) work by registering a function that is to be executed once the main part of the page has been loaded. If there are several scripts (gadgets or others) active, they each will register their own function. These functions will then be run in the order they were registered once the page is ready.

The problem with this is that if one of these registered functions has an error and crashes (raises an exception), those functions that were registered later won't be run at all. That can have hard-to-track and usually unwanted effects.

Lupo has added to Commons' MediaWiki:Common.js such that exceptions from these "onload" functions get caught. That code catches such exceptions and logs them, thereby making sure that all registered functions get called even if some of them fail.

The question now is where to log these errors, and who should see them. Currently, that code tries to log them to the browser's "error console", if possible, and displays the errors on the page only if that fails or if the user viewing the page is a sysop. (That's based on the assumption that sysops are typically the only ones who can do something about JS errors, since most of our scripts reside in protected pages anyway.) Non-sysop users would see these errors only if their browser had no "error console". But I could just as well suppress error messages for non-sysop users completely, or suppress them for anyone by default and show them only for users who put a certain flag in their monobook.js.

The code was tested on IE6 (alas, no source info), FF3.0.7 with Firebug 1.3.3, Safari 3.2.2 (Webkit 525.28.1), Opera 9.6.3. When people complain about strange things that might be connected with our JavaScript (such as gadgets not working or not having a category bar on the upload form), tell them to look at the top of the page whether there's some error message there.

Of course, ideally, one would fix this in wikibits.js directly. They should have written the onload hook handling from the very beginning such that it doesn't break when one hook fails. Wikibits could also give us a better jsMsg, and addPortletLink could be written such that it also works on the old skins (see e.g. function addToolLink in MediaWiki:Utilities.js). It could also offer a very minimal set of common JavaScript enhancements (such as String.trim or Function.bind, and other simple commonly used and often re-implemented stuff). But frankly said, I have no patience. Getting a change into wikibits means opening a bugzilla "enhancement" bug report, and these get low priority. If something like this ever goes into wikibits, great. But I wanted it now.
Comment 1 Lupo 2009-03-18 21:44:54 UTC
Created attachment 5940 [details]
Patch to wikibits.js for bug 18039

Attached is a patch for implementing the mechanism I used at the Commons directly in wikibits.js. Note that this is a slightly stripped-down version; I didn't want to include the "use window.console for logging if available" bit in the patch. If you want that, too, take a look at function Logger.log_exception in
http://commons.wikimedia.org/wiki/MediaWiki:Common.js
Comment 2 Lupo 2009-03-18 21:50:56 UTC
Didn't actually read what Mike had copied from the Commons discussion. Note that patch 5940 is only for the onload hook wrapping and exception logging (done using jsMsg), not about any other stuff that was mentioned on-wiki.
Comment 3 p858snake 2011-04-30 00:09:33 UTC
*Bulk BZ Change: +Patch to open bugs with patches attached that are missing the keyword*
Comment 4 Sumana Harihareswara 2011-11-10 06:08:54 UTC
I'm sorry for the wait, Lupo.  Thanks for your patch.  I'm adding keywords to ask for review.
Comment 5 Lupo 2011-11-10 10:11:22 UTC
I rather think that this whole issue has been long obsoleted by the ResourceLoader development and jQuery deployment. I don't think it needs review; just close it as resolved/obsoleted.
Comment 6 Sumana Harihareswara 2011-11-10 12:32:52 UTC
OK.  Thanks again, Lupo.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links