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

Sta*_*lfi 5 javascript google-chrome-devtools rxjs angular-cli angular

我正在使用 angular-cli 构建一个小型 angular2 Web 应用程序,并且正在使用 chrome dev-tools 进行调试。

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

以这个错误为例:

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 
Run Code Online (Sandbox Code Playgroud)

问题:

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

我的问题:

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

  1. 在我的代码中订阅那个 observable 的地方发生了。
  2. 如果它是 ngrx 的可观察对象,那么在我的代码中,有人调度了导致错误的那个动作。

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

Ben*_*esh 1

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

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

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