From 6624e5c67e51b2a61c5f15ce2196527c158fec12 Mon Sep 17 00:00:00 2001 From: Carlis Liu Date: Thu, 27 Jul 2017 16:59:29 +0800 Subject: [PATCH] catch error when set error@context prop --- context.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/context.js b/context.js index e729e45..226cc51 100644 --- a/context.js +++ b/context.js @@ -49,9 +49,10 @@ Namespace.prototype.run = function (fn) { return context; } catch (exception) { - if (exception) { + try { exception[ERROR_SYMBOL] = context; } + catch (e) {} throw exception; } finally { @@ -84,9 +85,10 @@ Namespace.prototype.bind = function (fn, context) { return fn.apply(this, arguments); } catch (exception) { - if (exception) { + try { exception[ERROR_SYMBOL] = context; } + catch (e) {} throw exception; } finally { @@ -161,7 +163,7 @@ Namespace.prototype.bindEmitter = function (emitter) { * @param {Error} exception Possibly annotated error. */ Namespace.prototype.fromException = function (exception) { - return exception[ERROR_SYMBOL]; + return exception && exception[ERROR_SYMBOL]; }; function get(name) {