Krinkle has uploaded a new change for review.
https://gerrit.wikimedia.org/r/91911
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
---
M resources/mediawiki/mediawiki.js
M resources/mediawiki/mediawiki.user.js
2 files changed, 28 insertions(+), 27 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/11/91911/1
diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js
index cc996e5..5e32e7a 100644
--- a/resources/mediawiki/mediawiki.js
+++ b/resources/mediawiki/mediawiki.js
@@ -10,6 +10,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 */
/**
@@ -592,7 +616,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 +795,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 +847,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 +1009,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 );
}
diff --git a/resources/mediawiki/mediawiki.user.js
b/resources/mediawiki/mediawiki.user.js
index 3e375fb..eeafbdd 100644
--- a/resources/mediawiki/mediawiki.user.js
+++ b/resources/mediawiki/mediawiki.user.js
@@ -10,6 +10,7 @@
options = mw.user.options || new mw.Map(),
tokens = mw.user.tokens || new mw.Map();
+
/**
* Get the current user's groups or rights
*
--
To view, visit https://gerrit.wikimedia.org/r/91911
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id5b9872e2050326ab83889e3a806d015ec2ff3eb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits