From 728456606135369d260f9cbc9ca0ccdb5763cbf8 Mon Sep 17 00:00:00 2001 From: Eelco Wiersma Date: Mon, 25 Nov 2019 19:46:03 +0100 Subject: [PATCH] Fix Meteor #7679 Based on https://github.com/meteorhacks/kadira/pull/258 --- lib/hijack/wrap_session.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/hijack/wrap_session.js b/lib/hijack/wrap_session.js index 87196a91..824c4e3e 100644 --- a/lib/hijack/wrap_session.js +++ b/lib/hijack/wrap_session.js @@ -160,12 +160,27 @@ function wrapMethodHanderForErrors(name, originalHandler, methodMap) { try{ return originalHandler.apply(this, arguments); } catch(ex) { + // create a kadira exception + // don't change the original exception so that + // Meteor output of the exception is not impacted + // Meteor #7679 + var kex; if(ex && Kadira._getInfo()) { // sometimes error may be just an string or a primitive // in that case, we need to make it a psuedo error if(typeof ex !== 'object') { - ex = {message: ex, stack: ex}; + kex = {message: ex, stack: ex}; + } else { + // create a new error via constructor + // set stack properly + if(ex.constructor) { + kex = new ex.constructor(); + kex.message = ex.message; + } else { + kex = {message: ex.message}; + } } + // Now we are marking this error to get tracked via methods // But, this also triggers a Meteor.debug call and // it only gets the stack @@ -173,9 +188,9 @@ function wrapMethodHanderForErrors(name, originalHandler, methodMap) { // tracking this error. That's why we do this // See Meteor.debug error tracking code for more if (Kadira.options.enableErrorTracking) { - ex.stack = {stack: ex.stack, source: 'method'}; + kex.stack = {stack: kex.stack, source: 'method'}; } - Kadira._getInfo().currentError = ex; + Kadira._getInfo().currentError = kex; } throw ex; }