Skip to content

Commit

Permalink
re-define error stack instead of setting it
Browse files Browse the repository at this point in the history
Fixes #552
  • Loading branch information
petkaantonov committed Mar 30, 2015
1 parent 994c0ba commit f06361b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/captured_trace.js
Expand Up @@ -100,7 +100,7 @@ CapturedTrace.prototype.attachExtraTrace = function(error) {
}
removeCommonRoots(stacks);
removeDuplicateOrEmptyJumps(stacks);
error.stack = reconstructStack(message, stacks);
util.notEnumerableProp(error, "stack", reconstructStack(message, stacks));
util.notEnumerableProp(error, "__stackCleaned__", true);
};

Expand Down
3 changes: 2 additions & 1 deletion src/debuggability.js
Expand Up @@ -105,7 +105,8 @@ Promise.prototype._attachExtraTrace = function (error, ignoreSelf) {
trace.attachExtraTrace(error);
} else if (!error.__stackCleaned__) {
var parsed = CapturedTrace.parseStackAndMessage(error);
error.stack = parsed.message + "\n" + parsed.stack.join("\n");
util.notEnumerableProp(error, "stack",
parsed.message + "\n" + parsed.stack.join("\n"));
util.notEnumerableProp(error, "__stackCleaned__", true);
}
}
Expand Down
21 changes: 21 additions & 0 deletions test/mocha/error.js
Expand Up @@ -115,6 +115,27 @@ describe("Promise.prototype.error", function(){
});
})

if (testUtils.ecmaScript5) {
describe("Weird errors", function() {
specify("unwritable stack", function() {
var e = new Error();
var stack = e.stack;
Object.defineProperty(e, "stack", {
configurable: true,
get: function() {return stack;},
set: function() {throw new Error("cannot set");}
});
return new Promise(function(_, reject) {
setTimeout(function() {
reject(e);
}, 1);
}).catch(function(err) {
assert.equal(e, err);
});
});
});
}

describe("Error constructors", function() {
describe("OperationalError", function() {
it("should work without new", function() {
Expand Down

0 comments on commit f06361b

Please sign in to comment.