From 7e22e7e7512bbffc87edbfcc95fe25b70913cab0 Mon Sep 17 00:00:00 2001 From: brucejo Date: Thu, 30 Mar 2017 15:44:26 -0700 Subject: [PATCH 1/4] Fix Meteor 7679. Don't modify exception that is handled by Meteor. --- lib/hijack/wrap_session.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/hijack/wrap_session.js b/lib/hijack/wrap_session.js index 33fb3dbf..8a1944b1 100644 --- a/lib/hijack/wrap_session.js +++ b/lib/hijack/wrap_session.js @@ -163,11 +163,25 @@ 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 = ex.constructor(ex.message); + kex.stack = ex.stack; + } else { + kex = {message: ex.message, stack: ex.stack}; + } } // Now we are marking this error to get tracked via methods // But, this also triggers a Meteor.debug call and @@ -175,8 +189,8 @@ function wrapMethodHanderForErrors(name, originalHandler, methodMap) { // We also track Meteor.debug errors and want to stop // tracking this error. That's why we do this // See Meteor.debug error tracking code for more - ex.stack = {stack: ex.stack, source: 'method'}; - Kadira._getInfo().currentError = ex; + kex.stack = {stack: kex.stack, source: 'method'}; + Kadira._getInfo().currentError = kex; } throw ex; } From a0c338fe0b31647c5f76765365a287adb3198ce9 Mon Sep 17 00:00:00 2001 From: brucejo Date: Thu, 30 Mar 2017 15:45:55 -0700 Subject: [PATCH 2/4] Revert "Fix Meteor 7679. Don't modify exception that is handled by Meteor." This reverts commit 7e22e7e7512bbffc87edbfcc95fe25b70913cab0. --- lib/hijack/wrap_session.js | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/lib/hijack/wrap_session.js b/lib/hijack/wrap_session.js index 8a1944b1..33fb3dbf 100644 --- a/lib/hijack/wrap_session.js +++ b/lib/hijack/wrap_session.js @@ -163,25 +163,11 @@ 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') { - kex = {message: ex, stack: ex}; - } else { - // create a new error via constructor - // set stack properly - if(ex.constructor) { - kex = ex.constructor(ex.message); - kex.stack = ex.stack; - } else { - kex = {message: ex.message, stack: ex.stack}; - } + ex = {message: ex, stack: ex}; } // Now we are marking this error to get tracked via methods // But, this also triggers a Meteor.debug call and @@ -189,8 +175,8 @@ function wrapMethodHanderForErrors(name, originalHandler, methodMap) { // We also track Meteor.debug errors and want to stop // tracking this error. That's why we do this // See Meteor.debug error tracking code for more - kex.stack = {stack: kex.stack, source: 'method'}; - Kadira._getInfo().currentError = kex; + ex.stack = {stack: ex.stack, source: 'method'}; + Kadira._getInfo().currentError = ex; } throw ex; } From ec5550916a6be618a41e1440d52d1cfe6c7d437c Mon Sep 17 00:00:00 2001 From: brucejo Date: Thu, 30 Mar 2017 15:47:38 -0700 Subject: [PATCH 3/4] Fix Meteor 7679. Don't change exception that is handled by Meteor. --- lib/hijack/wrap_session.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/hijack/wrap_session.js b/lib/hijack/wrap_session.js index 33fb3dbf..8a1944b1 100644 --- a/lib/hijack/wrap_session.js +++ b/lib/hijack/wrap_session.js @@ -163,11 +163,25 @@ 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 = ex.constructor(ex.message); + kex.stack = ex.stack; + } else { + kex = {message: ex.message, stack: ex.stack}; + } } // Now we are marking this error to get tracked via methods // But, this also triggers a Meteor.debug call and @@ -175,8 +189,8 @@ function wrapMethodHanderForErrors(name, originalHandler, methodMap) { // We also track Meteor.debug errors and want to stop // tracking this error. That's why we do this // See Meteor.debug error tracking code for more - ex.stack = {stack: ex.stack, source: 'method'}; - Kadira._getInfo().currentError = ex; + kex.stack = {stack: kex.stack, source: 'method'}; + Kadira._getInfo().currentError = kex; } throw ex; } From 37e3e52fee8a6e47cc6d624866175281698c819d Mon Sep 17 00:00:00 2001 From: brucejo Date: Fri, 31 Mar 2017 12:12:58 -0700 Subject: [PATCH 4/4] handle objects more generally, handle nostack case --- lib/hijack/wrap_session.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/hijack/wrap_session.js b/lib/hijack/wrap_session.js index 8a1944b1..af8a4338 100644 --- a/lib/hijack/wrap_session.js +++ b/lib/hijack/wrap_session.js @@ -177,12 +177,13 @@ function wrapMethodHanderForErrors(name, originalHandler, methodMap) { // create a new error via constructor // set stack properly if(ex.constructor) { - kex = ex.constructor(ex.message); - kex.stack = ex.stack; + kex = new ex.constructor(); + kex.message = ex.message; } else { - kex = {message: ex.message, stack: ex.stack}; + kex = {message: ex.message}; } } + if(ex.stack) kex.stack = ex.stack; // 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