Skip to content

Commit

Permalink
fix(subscribe): ignore syncError when deprecated (#3749)
Browse files Browse the repository at this point in the history
* test(catchError): add failing test

* fix(subscribe): ignore syncError when deprecated

Unless using the deprecated syncError handling, the syncErrorThrowable
flag should be ignored.
  • Loading branch information
cartant authored and benlesh committed May 31, 2018
1 parent 3746c41 commit f94560c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
17 changes: 16 additions & 1 deletion spec/operators/catch-spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<string>(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;

Expand Down
6 changes: 5 additions & 1 deletion src/internal/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ export class Observable<T> implements Subscribable<T> {
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) {
Expand Down

0 comments on commit f94560c

Please sign in to comment.