question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Errors being trapped by merge operations like switchMaps

See original GitHub issue

RxJS version: 5.5.5

Code to reproduce:

EDIT: Ugh, the code I had to reproduce this didn’t reproduce it as expected… but I’ve seen a non-trivial reproduction. cc @IgorMinar

Expected behavior: Error “final error” should be reported in console

Actual behavior: Error is squeltched.

Additional information: This only happens if the observable in the merge operation is asynchronous. The error thrown by the subscription unwinds the stack back to the switchMap’s subscriber (via parent.notifyError from InnerSubscriber), and it’s swallowed because the switchMap subscriber isStopped.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
IgorMinarcommented, Dec 13, 2017

@jayphelps that build didn’t work because it’s not complete (all add/operator/* files are missing), but I was able to diff it and extract this patch that I applied to my current build:

--- node_modules/rxjs.patched/src/Subscriber.ts 2017-12-06 09:58:33.000000000 -0800
+++ node_modules/rxjs/src/Subscriber.ts 2017-12-05 01:29:16.000000000 -0800
@@ -68,6 +68,7 @@
         }
         if (typeof destinationOrNext === 'object') {
           if (destinationOrNext instanceof Subscriber) {
+            this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;
             this.destination = (<Subscriber<any>> destinationOrNext);
             (<any> this.destination).add(this);
           } else {

--- node_modules/rxjs.patched/src/Observable.ts 2017-12-06 09:58:33.000000000 -0800
+++ node_modules/rxjs/src/Observable.ts 2017-12-05 01:29:16.000000000 -0800
@@ -199,7 +199,7 @@
     if (operator) {
       operator.call(sink, this.source);
     } else {
-      sink.add(this.source ? this._subscribe(sink) : this._trySubscribe(sink));
+      sink.add(this.source || !sink.syncErrorThrowable ? this._subscribe(sink) : this._trySubscribe(sink));
     }

     if (sink.syncErrorThrowable) {

With this patch applied to the JS files by hand, I was able to confirm that the errors now get propagated correctly, so if I extracted the change correctly, then what you did resolves the problem.

0reactions
lock[bot]commented, Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RXJS v6.4 switchMap operator returns an Observable rather ...
I am running an Angular 8 app, and I am getting an error which seems to be a major bug in RxJS or...
Read more >
RxJS: Avoiding switchMap-related Bugs - ncjamieson
If switchMap is replaced with mergeMap , the effect/epic will concurrently handle each dispatched action. That is, pending removals will not be ...
Read more >
Controlling multiple HTTP requests with RxJS - esveo
switchMap if you need to wait for the result of a first request to start the second ; combineLatest if you need to...
Read more >
RxJs Mapping: switchMap vs mergeMap vs concatMap vs ...
Here is how the mergeMap operator works: each value of the source Observable is still being mapped into an inner Observable, just like...
Read more >
Reactor 3 Reference Guide
Then RxJava implemented reactive programming on the JVM. As time went on, a standardization for Java emerged through the Reactive Streams effort ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found