我正在使用bluebird 2.x。
我打电话给承诺里面的kafka。如果消息已发布,则承诺将得到解决。如果对卡夫卡的调用失败,则会拒绝承诺。
以下是导致错误的代码段 -
redis.get(something)
.then(function() {
return Promise(function(resolve, reject) { // This is Line 98 in the stacktrace
producer.send([
{
topic : "Ganga",
messages : [JSON.stringify({// some object})]
}
], function(err, data) {
if(err) {
logger.error("Error")
logger.error(err);
reject(err);
return;
}
resolve(data);
})
});
})
堆栈跟踪如下
TypeError: Cannot set property '_bitField' of undefined
at <project base path>/index.js:98:20
at bound (domain.js:280:14)
at runBound (domain.js:293:12)
at runCallback (timers.js:649:20)
at tryOnImmediate (timers.js:622:5)
at processImmediate [as _immediateCallback] (timers.js:594:5)
From previous event:
at Server.<anonymous> (<project base path>/index.js:97:10)
at next (<project base path>/node_modules/restify/lib/server.js:912:30)
at f (<project base path>/node_modules/once/once.js:25:25)
at Server.parseBody (<project base path>/node_modules/restify/lib/plugins/body_parser.js:94:13)
at next (<project base path>/node_modules/restify/lib/server.js:912:30)
at f (<project base path>/node_modules/once/once.js:25:25)
at IncomingMessage.done (<project base path>/node_modules/restify/lib/plugins/body_reader.js:121:13)
at IncomingMessage.g (events.js:292:16)
at emitNone (events.js:86:13)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
关于可能出错的任何建议?
答案 0 :(得分:2)
错误在第98行引发它肯定是因为在Promise之前没有使用new。