jenkins-bot has submitted this change and it was merged.

Change subject: Fix stack traces
......................................................................


Fix stack traces

Change-Id: I30766199ab157a0f6168d666a32261b1758807ae
---
M lib/LogData.js
1 file changed, 21 insertions(+), 11 deletions(-)

Approvals:
  Subramanya Sastry: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/LogData.js b/lib/LogData.js
index a9005b8..5f0fa50 100644
--- a/lib/LogData.js
+++ b/lib/LogData.js
@@ -14,10 +14,10 @@
  * @param {string} logType Type of log being generated.
  * @param {object} logObject Data being logged.
  */
-var LogData = function (logType, logObject) {
+var LogData = function(logType, logObject) {
        this.logType = logType;
        this.logObject = logObject;
-       this._error = logObject instanceof Error ? logObject : new Error();
+       this._error = new Error();
 
        // Cache log information if previously constructed.
        this._cache = {};
@@ -57,7 +57,7 @@
        return this._cache.msg;
 };
 
-LogData.prototype._getStack = function(e) {
+LogData.prototype._getStack = function() {
        // Save original Error.prepareStackTrace
        var origPrepareStackTrace = Error.prepareStackTrace;
 
@@ -65,14 +65,18 @@
        Error.prepareStackTrace = function (_, stack) { return stack; };
 
        // Remove superfluous function calls on stack
-       //  (In some cases, stacks are suppressed
-       //   See DoesNotExistError in mediawikiApiRequest.js)
-       var stack = !e.stack ? "" : 'Stack:\n  ' + e.stack.slice(2).join('\n  
');
+       var stack = this._error.stack;
+       for (var i = 0; i < stack.length - 1; i++) {
+               if ( /\.log \(/.test( stack[i] ) ) {
+                       stack = stack.slice(i + 1);
+                       break;
+               }
+       }
 
        // Restore original `Error.prepareStackTrace`
        Error.prepareStackTrace = origPrepareStackTrace;
 
-       return stack;
+       return "Stack:\n  " + stack.join('\n  ');
 };
 
 /**
@@ -85,7 +89,7 @@
 LogData.prototype.stack = function(){
        if (this._cache.stack === undefined) {
                this._cache.stack = this.flatLogObject().stack === undefined
-                       ? this._getStack(this._error) : 
this.flatLogObject().stack;
+                       ? this._getStack() : this.flatLogObject().stack;
        }
        return this._cache.stack;
 };
@@ -115,7 +119,7 @@
  * @param {String} topLevel Separate top-level from recursive calls.
  */
 LogData.prototype._flatten = function(o, topLevel) {
-       var f, stack, msg, longMsg,
+       var f, msg, longMsg,
        self = this;
 
        if ( typeof(o) === 'undefined' || o === null ) {
@@ -136,7 +140,13 @@
                        longMsg: longMsg
                });
        } else if (o instanceof Error) {
-               f = { msg: o.message, stack: this._getStack(o) };
+               f = {
+                       msg: o.message,
+                       // In some cases, stacks are suppressed (See 
DoesNotExistError in
+                       // mediawikiApiRequest.js). We return a defined value 
to avoid 
+                       // generating a stack above.
+                       stack: o.stack || ""
+               };
                if ( o.code ) {
                        f.code = o.code;
                }
@@ -148,7 +158,7 @@
        } else if ( typeof(o) === 'string' ) {
                return { msg: o };
        } else {
-               return { msg: JSON.stringify(o)};
+               return { msg: JSON.stringify(o) };
        }
 };
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I30766199ab157a0f6168d666a32261b1758807ae
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: Marcoil <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to