From c4989744c2ba52237893167915590f20d93d8392 Mon Sep 17 00:00:00 2001 From: Jay Phelps Date: Tue, 5 Dec 2017 01:10:31 -0800 Subject: [PATCH 1/2] test(Observable): add failing test for syncErrorThrowable issue --- spec/Observable-spec.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/Observable-spec.ts b/spec/Observable-spec.ts index 16bdad8f6d..5b8eb18d75 100644 --- a/spec/Observable-spec.ts +++ b/spec/Observable-spec.ts @@ -59,6 +59,20 @@ describe('Observable', () => { }).to.throw(); }); + it('should rethrow if sink has syncErrorThrowable = false', () => { + const observable = new Observable(observer => { + observer.next(1); + }); + + const sink = Subscriber.create(() => { + throw 'error!'; + }); + + expect(() => { + observable.subscribe(sink); + }).to.throw('error!'); + }); + describe('forEach', () => { it('should iterate and return a Promise', (done: MochaDone) => { const expected = [1, 2, 3]; From 541b49db0ca4079760f92f670a49a8f06dc83dd2 Mon Sep 17 00:00:00 2001 From: Jay Phelps Date: Tue, 5 Dec 2017 01:13:50 -0800 Subject: [PATCH 2/2] fix(Observable): rethrow errors when syncErrorThrowable and inherit it from destination. Fixes #2813 --- src/Observable.ts | 2 +- src/Subscriber.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Observable.ts b/src/Observable.ts index 74bc9af34f..25ccebbde9 100644 --- a/src/Observable.ts +++ b/src/Observable.ts @@ -199,7 +199,7 @@ export class Observable implements Subscribable { 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) { diff --git a/src/Subscriber.ts b/src/Subscriber.ts index 36d8459191..daa1536416 100644 --- a/src/Subscriber.ts +++ b/src/Subscriber.ts @@ -68,6 +68,7 @@ export class Subscriber extends Subscription implements Observer { } if (typeof destinationOrNext === 'object') { if (destinationOrNext instanceof Subscriber) { + this.syncErrorThrowable = destinationOrNext.syncErrorThrowable; this.destination = (> destinationOrNext); ( this.destination).add(this); } else {