I'm trying to serialize an exception in an AWS lambda function, but when I do it, the object has no properties. Here is a simplified version of this:
exports.handler = function(event, context) {
try {
var x = some.property;
context.succeed(null);
} catch (err) {
console.log("error=" + JSON.stringify(err, null, 2));
context.fail(err);
}
};
Here's the log output. Note that when I JSON.stringify
the exception object, there's nothing there, but in the context.fail
line, the exception data is there.
START RequestId: 810913d1-567b-11e5-a0d1-95dad6b9184b
2015-09-08T22:46:55.308Z 810913d1-567b-11e5-a0d1-95dad6b9184b error={}
2015-09-08T22:46:55.368Z 810913d1-567b-11e5-a0d1-95dad6b9184b {"errorMessage":"some is not defined","errorType":"ReferenceError","stackTrace":["exports.handler (/var/task/index.js:5:17)"]}
END RequestId: 810913d1-567b-11e5-a0d1-95dad6b9184b
REPORT RequestId: 810913d1-567b-11e5-a0d1-95dad6b9184b Duration: 174.72 ms Billed Duration: 200 ms Memory Size: 128 MB Max Memory Used: 9 MB
Anyone know what might be happening?
The properties of the Exception might have been defined with Object.defineProperty
. if you run the following example, you'll see that they don't get serialized
function Exception () {
this.message = function () {
return 'Oh NOES';
};
}
Exception.prototype.constructor = Exception;
Object.defineProperty(Exception.prototype, 'foo', {
get: function () {
return this.message();
}
});
var e = new Exception();
console.log(e.foo) // 'Oh NOES'
console.log(JSON.stringify(e, null, 2)); // {}