使用 rxjs 时如何获取错误的堆栈跟踪?

How to get the stacktrace of an error when using rxjs?

我正在使用 angular-cli 构建一个小型 angular2 网络应用程序,我正在使用 chrome 开发工具进行调试。

如果我每次都需要猜测错误的根源在哪里以及该错误的堆栈跟踪是什么,显然我做错了什么。

以这个错误为例:

error_handler.js:45EXCEPTION: Cannot read property 'provider' of nullErrorHandler.handleError @ error_handler.js:45
error_handler.js:50ORIGINAL STACKTRACE:ErrorHandler.handleError @ error_handler.js:50
error_handler.js:51TypeError: Cannot read property 'provider' of null
    at MapSubscriber.project (auth.effects.ts:80)
    at MapSubscriber._next (map.js:77)
    at MapSubscriber.Subscriber.next (Subscriber.js:89)
    at DistinctUntilChangedSubscriber._next (distinctUntilChanged.js:72)
    at DistinctUntilChangedSubscriber.Subscriber.next (Subscriber.js:89)
    at MapSubscriber._next (map.js:83)
    at MapSubscriber.Subscriber.next (Subscriber.js:89)
    at MapSubscriber._next (map.js:83)
    at MapSubscriber.Subscriber.next (Subscriber.js:89)
    at RefCountSubscriber.Subscriber._next (Subscriber.js:125)ErrorHandler.handleError @ error_handler.js:51
zone.js:355Unhandled Promise rejection: Cannot read property 'provider' of null ; Zone: <root> ; Task: Promise.then ; Value: TypeError: Cannot read property 'provider' of null(…) TypeError: Cannot read property 'provider' of null
    at MapSubscriber.project (http://localhost:4200/main.bundle.js:35342:83)
    at MapSubscriber._next (http://localhost:4200/main.bundle.js:4171:35)
    at MapSubscriber.Subscriber.next (http://localhost:4200/main.bundle.js:395:18)
    at DistinctUntilChangedSubscriber._next (http://localhost:4200/main.bundle.js:25485:30)
    at DistinctUntilChangedSubscriber.Subscriber.next (http://localhost:4200/main.bundle.js:395:18)
    at MapSubscriber._next (http://localhost:4200/main.bundle.js:4177:26)
    at MapSubscriber.Subscriber.next (http://localhost:4200/main.bundle.js:395:18)
    at MapSubscriber._next (http://localhost:4200/main.bundle.js:4177:26)
    at MapSubscriber.Subscriber.next (http://localhost:4200/main.bundle.js:395:18)
    at RefCountSubscriber.Subscriber._next (http://localhost:4200/main.bundle.js:431:26)consoleError @ zone.js:355
zone.js:357Error: Uncaught (in promise): TypeError: Cannot read property 'provider' of null
    at resolvePromise (http://localhost:4200/main.bundle.js:93214:31)
    at http://localhost:4200/main.bundle.js:93191:13
    at ZoneDelegate.invoke (http://localhost:4200/main.bundle.js:92988:28)
    at Zone.run (http://localhost:4200/main.bundle.js:92881:43)
    at http://localhost:4200/main.bundle.js:93247:57
    at ZoneDelegate.invokeTask (http://localhost:4200/main.bundle.js:93021:37)
    at Zone.runTask (http://localhost:4200/main.bundle.js:92921:47)
    at drainMicroTaskQueue (http://localhost:4200/main.bundle.js:93153:35)consoleError @ zone.js:357 

问题:

这个错误对我来说毫无意义。它完全无用且不可读。 幸运的是,我看到了这一行(有时我没有得到任何错误所在的指示):at MapSubscriber.project (auth.effects.ts:80) - 这一行是唯一有用的行,在这里可以了解如何修复该错误。 试图理解堆栈跟踪将毫无意义,因为它都是 rxjs 堆栈跟踪。

我的问题:

我想知道我的代码的堆栈跟踪。这可能吗?

  1. 在我的代码中发生了对该可观察对象的订阅。
  2. 如果它是来自 ngrx 的可观察对象,那么在我的代码中有人发送了导致错误的操作。

关于如何使用 rxjs 调试异步代码然后修复这个特定错误的更一般的问题。

它发生在您提供给 map 操作员的投影方法中。线索位于堆栈的顶部。 MapSubscriber.project.

基本上您从顶部读取堆栈跟踪。最上面的调用是抛出(或重新抛出)错误的地方。

在 RxJS 5 中,每个运算符通常有两到三个调用。每个运营商都有一个以其名字命名的订阅者来完成这项工作。 MapSubscriber.Subscriber.next MapSubscriber._next