1

Rollbar用来处理未捕获的异常和拒绝。 rollbar.handleUncaughtExceptionsAndRejections("...")

当错误在 Promise 中时,日志根本没有用,这里有一个例子request-promise

StatusCodeError: 503 - {"message":"Service Unavailable","error":503}
at new StatusCodeError (/opt/example/app/node_modules/@request/promise-core/lib/errors.js line 32 col 15)
Error.captureStackTrace(this);
at Request.plumbing.callback (/opt/example/app/node_modules/@request/promise-core/lib/plumbing.js line 95 col 33)
self._rp_reject(new errors.StatusCodeError(response.statusCode, body, self._rp_options, response));
at Request.RP$callback [as _callback] (/opt/example/app/node_modules/@request/promise-core/lib/plumbing.js line 37 col 31)
plumbing.callback.call(self, err, response, body);
at Request.self.callback (/opt/example/app/node_modules/request/request.js line 187 col 22)
self._callback.apply(self, arguments)
at emitTwo (events.js line 106 col 13)
at Request.emit (events.js line 191 col 7)
at Request.<anonymous> (/opt/example/app/node_modules/request/request.js line 1044 col 10)
self.emit('complete', response, response.body)
at emitOne (events.js line 96 col 13)
at Request.emit (events.js line 188 col 7)
at IncomingMessage.<anonymous> (/opt/example/app/node_modules/request/request.js line 965 col 12)
self.emit('end', chunk)
at emitNone (events.js line 91 col 20)
at IncomingMessage.emit (events.js line 185 col 7)
at endReadableNT (_stream_readable.js line 934 col 12)
at _combinedTickCallback (internal/process/next_tick.js line 74 col 11)
at process._tickDomainCallback (internal/process/next_tick.js line 122 col 9)

这是一个bluebird例子:

TypeError: Cannot read property 'data' of undefined
at String.eval (eval at <anonymous> (/opt/example/app/node_modules/bluebird/js/release/call_get.js:36:12), <anonymous> line 5 col 19)
at String.tryCatcher (/opt/example/app/node_modules/bluebird/js/release/util.js line 16 col 23)
return target.apply(this, arguments);
at Promise._settlePromiseFromHandler (/opt/example/app/node_modules/bluebird/js/release/promise.js line 504 col 31)
x = tryCatch(handler).call(receiver, value);
at Promise._settlePromise (/opt/example/app/node_modules/bluebird/js/release/promise.js line 561 col 18)
this._settlePromiseFromHandler(handler, receiver, value, promise);
at Promise._settlePromise0 (/opt/example/app/node_modules/bluebird/js/release/promise.js line 606 col 10)
this._settlePromise(promise, handler, receiver, value);
at Promise._settlePromises (/opt/example/app/node_modules/bluebird/js/release/promise.js line 685 col 18)
this._settlePromise0(this._fulfillmentHandler0, value, bitField);
at Async._drainQueue (/opt/example/app/node_modules/bluebird/js/release/async.js line 138 col 16)
fn._settlePromises();
at Async._drainQueues (/opt/example/app/node_modules/bluebird/js/release/async.js line 148 col 10)
this._drainQueue(this._normalQueue);
at Immediate.Async.drainQueues (/opt/example/app/node_modules/bluebird/js/release/async.js line 17 col 14)
self._drainQueues();
at runCallback (timers.js line 570 col 20)
at tryOnImmediate (timers.js line 550 col 5)
at processImmediate [as _immediateCallback] (timers.js line 529 col 5)

我该怎么做才能记录真正的错误位置?

4

1 回答 1

0

使用 Blueibird 启用未处理的拒绝以获取完整的堆栈跟踪:

Promise.config({ longStackTraces: true });

这应该会给你更多的信息错误,尽管它确实会产生小的速度损失。

于 2016-08-27T18:41:14.943 回答