Bartosz Dziewoński has submitted this change and it was merged.

Change subject: mediawiki.js: Handle error better in log() and move out of 
mw.loader
......................................................................


mediawiki.js: Handle error better in log() and move out of mw.loader

console.error (in Chrome dev tools) takes an Error object. It
renders the stack trace nicely (incl. dynamic references to files)
but doesn't stringify the exception itself. It renders it as an
object (eg. no "{}" instead of "TypeError: Foo bar").

Some of the callers were embedding e.message manually. That was
better though, that still omitted the class (eg. "TypeError").
Error#toString composes the full message incl. class name prefix.

Change-Id: Id5b9872e2050326ab83889e3a806d015ec2ff3eb
(cherry picked from commit 4f23099c223a7525774afd4d18b89cff22374581)
---
M resources/mediawiki/mediawiki.js
1 file changed, 33 insertions(+), 36 deletions(-)

Approvals:
  Bartosz Dziewoński: Verified; Looks good to me, approved



diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js
index cc996e5..c470186 100644
--- a/resources/mediawiki/mediawiki.js
+++ b/resources/mediawiki/mediawiki.js
@@ -1,5 +1,9 @@
-/*
- * Core MediaWiki JavaScript Library
+/**
+ * Base library for MediaWiki.
+ *
+ * @class mw
+ * @alternateClassName mediaWiki
+ * @singleton
  */
 
 var mw = ( function ( $, undefined ) {
@@ -9,6 +13,30 @@
 
        var hasOwn = Object.prototype.hasOwnProperty,
                slice = Array.prototype.slice;
+
+       /**
+        * Log a message to window.console, if possible. Useful to force 
logging of some
+        * errors that are otherwise hard to detect (I.e., this logs also in 
production mode).
+        * Gets console references in each invocation, so that delayed 
debugging tools work
+        * fine. No need for optimization here, which would only result in 
losing logs.
+        *
+        * @private
+        * @param {string} msg text for the log entry.
+        * @param {Error} [e]
+        */
+       function log( msg, e ) {
+               var console = window.console;
+               if ( console && console.log ) {
+                       console.log( msg );
+                       // If we have an exception object, log it through 
.error() to trigger
+                       // proper stacktraces in browsers that support it. 
There are no (known)
+                       // browsers that don't support .error(), that do 
support .log() and
+                       // have useful exception handling through .log().
+                       if ( e && console.error ) {
+                               console.error( String( e ), e );
+                       }
+               }
+       }
 
        /* Object constructors */
 
@@ -290,13 +318,6 @@
                }
        };
 
-       /**
-        * Base library for MediaWiki.
-        *
-        * @class mw
-        * @alternateClassName mediaWiki
-        * @singleton
-        */
        return {
                /* Public Members */
 
@@ -592,7 +613,7 @@
                                                        try {
                                                                
styleEl.styleSheet.cssText += cssText; // IE
                                                        } catch ( e ) {
-                                                               log( 
'addEmbeddedCSS fail\ne.message: ' + e.message, e );
+                                                               log( 
'addEmbeddedCSS fail', e );
                                                        }
                                                } else {
                                                        styleEl.appendChild( 
document.createTextNode( String( cssText ) ) );
@@ -771,30 +792,6 @@
                        }
 
                        /**
-                        * Log a message to window.console, if possible. Useful 
to force logging of some
-                        * errors that are otherwise hard to detect (I.e., this 
logs also in production mode).
-                        * Gets console references in each invocation, so that 
delayed debugging tools work
-                        * fine. No need for optimization here, which would 
only result in losing logs.
-                        *
-                        * @private
-                        * @param {string} msg text for the log entry.
-                        * @param {Error} [e]
-                        */
-                       function log( msg, e ) {
-                               var console = window.console;
-                               if ( console && console.log ) {
-                                       console.log( msg );
-                                       // If we have an exception object, log 
it through .error() to trigger
-                                       // proper stacktraces in browsers that 
support it. There are no (known)
-                                       // browsers that don't support 
.error(), that do support .log() and
-                                       // have useful exception handling 
through .log().
-                                       if ( e && console.error ) {
-                                               console.error( e );
-                                       }
-                               }
-                       }
-
-                       /**
                         * A module has entered state 'ready', 'error', or 
'missing'. Automatically update pending jobs
                         * and modules that depend upon this module. if the 
given module failed, propagate the 'error'
                         * state up the dependency tree; otherwise, execute all 
jobs/modules that now have all their
@@ -847,7 +844,7 @@
                                                                } catch ( ex ) {
                                                                        // A 
user-defined operation raised an exception. Swallow to protect
                                                                        // our 
state machine!
-                                                                       log( 
'Exception thrown by job.error()', ex );
+                                                                       log( 
'Exception thrown by job.error', ex );
                                                                }
                                                        }
                                                }
@@ -1009,7 +1006,7 @@
                                        } catch ( e ) {
                                                // This needs to NOT use mw.log 
because these errors are common in production mode
                                                // and not in debug mode, such 
as when a symbol that should be global isn't exported
-                                               log( 'Exception thrown by ' + 
module + ': ' + e.message, e );
+                                               log( 'Exception thrown by ' + 
module, e );
                                                registry[module].state = 
'error';
                                                handlePending( module );
                                        }

-- 
To view, visit https://gerrit.wikimedia.org/r/91986
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id5b9872e2050326ab83889e3a806d015ec2ff3eb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: REL1_22
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to