Page MenuHomePhabricator

Wrap scripts with exception handling for automatic JS error logging
Closed, DeclinedPublic

Description

Automagically wrap scripts in try...catch blocks to improve error reporting:

  • use ResourceLoader::makeLoaderImplementScript() to wrap source code in a try...catch block which passes the exception to the error logger
  • manipulate $, window etc. so that every top-scope call (event handlers, setTimeout etc) can be automatically wrapped in exception handling (probably a fair coverage could be achieved by decorating $.on, $.ready, $.ajax and window.setTimeout/setInterval).
  • create a browser testing suite to make sure no grade-A browser is broken by replacing native functions like setTimout (or ensure others did this already - sinon.js maybe?)

This is an alternative to using window.onerror (and as such an alternative to working around its problems - T508, T512). This might turn out to be too fragile or impractical to be worth doing. (Also, it probably won't work in debug mode when scripts are not minified.)

Event Timeline

Tgr claimed this task.
Tgr raised the priority of this task from to Medium.
Tgr updated the task description. (Show Details)
Tgr changed Security from none to None.
Tgr added a subscriber: Tgr.
Tgr renamed this task from Wrap scripts with exception handling to Wrap scripts with exception handling for automatic JS error logging.Oct 1 2014, 10:16 AM
Tgr removed Tgr as the assignee of this task.Jan 30 2015, 2:38 AM
gerritbot added a subscriber: gerritbot.

Change 188328 had a related patch set uploaded (by Gergő Tisza):
Wrap asynchronous callbacks with error logging

https://gerrit.wikimedia.org/r/188328

Patch-For-Review

Change 188327 had a related patch set uploaded (by Gergő Tisza):
Allow subscribing to module loading exceptions

https://gerrit.wikimedia.org/r/188327

Patch-For-Review

Change 188327 merged by jenkins-bot:
Allow subscribing to module loading exceptions

https://gerrit.wikimedia.org/r/188327

Change 188328 abandoned by Gergő Tisza:
Wrap asynchronous callbacks with error logging

Reason:
Abandoning, see T92247#1147500. Might be revisited later.

https://gerrit.wikimedia.org/r/188328

Tgr changed the task status from Open to Stalled.Mar 25 2015, 11:42 PM

We are not doing this for the first iteration - might be revisited when we have data on how much it would improve the coverage. See T92247 #1147500.

At the time of creating this task it was assumed that the server side implementation of error logging would be based on Sentry. We have eventually decided on a different implementation, so de-tagging.

Aklapper edited subscribers, added: Aklapper; removed: wikibugs-l-list.

Is this still wanted? If it is, in which codebase would this have to happen?

No reply; bolding declining as it is unclear which codebase this refers to. Please reopen if this is still valid and you can identify a codebase. Thanks!

The error logging code is in WikimediaEvents currently. This is probably not wanted, though. Manual catching and logging of errors is enabled by rMW9c077d443a58: mediawiki.base: Add mw.errorLogger.logError(); automatic catching has been deemed too intrusive.