From 445dfe45cc3d828015871e0b00d3623ed7f83d7c Mon Sep 17 00:00:00 2001 From: Nicholas Jamieson Date: Sat, 26 May 2018 12:34:39 +1000 Subject: [PATCH 1/2] test(catchError): add failing test --- spec/operators/catch-spec.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/spec/operators/catch-spec.ts b/spec/operators/catch-spec.ts index 37e9aee73f..7994f67c9f 100644 --- a/spec/operators/catch-spec.ts +++ b/spec/operators/catch-spec.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { of, throwError, EMPTY, from } from 'rxjs'; +import { concat, Observable, of, throwError, EMPTY, from } from 'rxjs'; import { catchError, map, mergeMap } from 'rxjs/operators'; import { TestScheduler } from 'rxjs/testing'; import * as sinon from 'sinon'; @@ -285,6 +285,21 @@ describe('catchError operator', () => { }); }); + it('should catch errors throw from within the constructor', () => { + // See https://github.com/ReactiveX/rxjs/issues/3740 + const source = concat( + new Observable(o => { + o.next('a'); + throw 'kaboom'; + }).pipe( + catchError(_ => of('b')) + ), + of('c') + ); + const expected = '(abc|)'; + expectObservable(source).toBe(expected); + }); + context('fromPromise', () => { type SetTimeout = (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; From 44e1a2733423cb88225c078ee1523397b127a1a7 Mon Sep 17 00:00:00 2001 From: Nicholas Jamieson Date: Sat, 26 May 2018 12:38:17 +1000 Subject: [PATCH 2/2] fix(subscribe): ignore syncError when deprecated Unless using the deprecated syncError handling, the syncErrorThrowable flag should be ignored. --- src/internal/Observable.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/internal/Observable.ts b/src/internal/Observable.ts index 01958375c3..349e2e1e4e 100644 --- a/src/internal/Observable.ts +++ b/src/internal/Observable.ts @@ -194,7 +194,11 @@ export class Observable implements Subscribable { if (operator) { operator.call(sink, this.source); } else { - sink.add(this.source || !sink.syncErrorThrowable ? this._subscribe(sink) : this._trySubscribe(sink)); + sink.add( + this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ? + this._subscribe(sink) : + this._trySubscribe(sink) + ); } if (config.useDeprecatedSynchronousErrorHandling) {