From d7bffa90febc08071876c6b8fe893517d84a74b1 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Sun, 13 Aug 2017 21:35:53 -0700 Subject: [PATCH 1/2] fix(subscribeToResult): throw error in subscriber with inner observable - closes #2618 --- src/util/subscribeToResult.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/subscribeToResult.ts b/src/util/subscribeToResult.ts index ae19fe5795..944921e17f 100644 --- a/src/util/subscribeToResult.ts +++ b/src/util/subscribeToResult.ts @@ -30,6 +30,7 @@ export function subscribeToResult(outerSubscriber: OuterSubscriber, destination.complete(); return null; } else { + destination.syncErrorThrowable = true; return result.subscribe(destination); } } else if (isArrayLike(result)) { From c935bf5987f0c1d726362964ff75701dcd7eba79 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Sun, 13 Aug 2017 22:56:47 -0700 Subject: [PATCH 2/2] test(subscribeToResult): add test cases for subscriber exception --- spec/util/subscribeToResult-spec.ts | 35 ++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/spec/util/subscribeToResult-spec.ts b/spec/util/subscribeToResult-spec.ts index 57b4b259aa..cfba7dea0b 100644 --- a/spec/util/subscribeToResult-spec.ts +++ b/spec/util/subscribeToResult-spec.ts @@ -1,9 +1,11 @@ -import {expect} from 'chai'; +import { expect } from 'chai'; import * as Rx from '../../dist/cjs/Rx'; -import {subscribeToResult} from '../../dist/cjs/util/subscribeToResult'; -import {OuterSubscriber} from '../../dist/cjs/OuterSubscriber'; -import {$$iterator} from '../../dist/cjs/symbol/iterator'; +import { subscribeToResult } from '../../dist/cjs/util/subscribeToResult'; +import { OuterSubscriber } from '../../dist/cjs/OuterSubscriber'; +import { $$iterator } from '../../dist/cjs/symbol/iterator'; import $$symbolObservable from 'symbol-observable'; +import { Observable } from '../../dist/cjs/Observable'; +import { Subject } from '../../dist/cjs/Subject'; describe('subscribeToResult', () => { it('should synchronously complete when subscribe to scalarObservable', () => { @@ -59,7 +61,7 @@ describe('subscribeToResult', () => { }); it('should subscribe to an array-like and emit synchronously', () => { - const result = {0: 0, 1: 1, 2: 2, length: 3}; + const result = { 0: 0, 1: 1, 2: 2, length: 3 }; const expected = []; const subscriber = new OuterSubscriber(x => expected.push(x)); @@ -105,12 +107,13 @@ describe('subscribeToResult', () => { const iterable = { [$$iterator]: () => { - return { - next: () => { - return iteratorResults.shift(); - } - }; - }}; + return { + next: () => { + return iteratorResults.shift(); + } + }; + } + }; const subscriber = new OuterSubscriber((x: number) => expected = x); @@ -177,4 +180,14 @@ describe('subscribeToResult', () => { subscribeToResult(subscriber, null); }); + + it('should not swallow exception in inner subscriber', () => { + const source = new Subject(); + + source.mergeMapTo(Observable.of(1, 2, 3)).subscribe(() => { + throw new Error('meh'); + }); + + expect(() => source.next()).to.throw(); + }); }); \ No newline at end of file