Skip to content

Commit aee824a

Browse files
msmithguQard
authored andcommitted
Make error context a non-enumerable property to avoid serialization errors (#75)
1 parent d5f3803 commit aee824a

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules/
2+
__testfile

context.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,13 @@ Namespace.prototype.run = function (fn) {
4949
return context;
5050
}
5151
catch (exception) {
52-
if (exception) {
53-
exception[ERROR_SYMBOL] = context;
52+
if (exception && !exception[ERROR_SYMBOL]) {
53+
Object.defineProperty(exception, ERROR_SYMBOL, {
54+
configurable: true,
55+
enumerable: false,
56+
writable: false,
57+
value: context
58+
});
5459
}
5560
throw exception;
5661
}
@@ -76,8 +81,13 @@ Namespace.prototype.bind = function (fn, context) {
7681
return fn.apply(this, arguments);
7782
}
7883
catch (exception) {
79-
if (exception) {
80-
exception[ERROR_SYMBOL] = context;
84+
if (exception && !exception[ERROR_SYMBOL]) {
85+
Object.defineProperty(exception, ERROR_SYMBOL, {
86+
configurable: true,
87+
enumerable: false,
88+
writable: false,
89+
value: context
90+
});
8191
}
8292
throw exception;
8393
}

0 commit comments

Comments
 (0)