AWS lambda 函数中的异常为空
Exception in AWS lambda function is empty
我正在尝试序列化 AWS lambda 函数中的异常,但是当我这样做时,该对象没有任何属性。这是一个简化版本:
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);
}
};
这是日志输出。请注意,当我 JSON.stringify
异常对象时,那里什么也没有,但是在 context.fail
行中,异常数据在那里。
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
有人知道会发生什么吗?
Exception 的属性可能已用 Object.defineProperty
定义。如果您 运行 以下示例,您会发现它们没有被序列化
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)); // {}
我正在尝试序列化 AWS lambda 函数中的异常,但是当我这样做时,该对象没有任何属性。这是一个简化版本:
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);
}
};
这是日志输出。请注意,当我 JSON.stringify
异常对象时,那里什么也没有,但是在 context.fail
行中,异常数据在那里。
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
有人知道会发生什么吗?
Exception 的属性可能已用 Object.defineProperty
定义。如果您 运行 以下示例,您会发现它们没有被序列化
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)); // {}