Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve run-time errors when using deprecated sync error handling #6272

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions spec/Observable-spec.ts
Expand Up @@ -799,6 +799,17 @@ describe('Observable', () => {
expect(results).to.deep.equal([1, 2]);
});

// https://github.com/ReactiveX/rxjs/issues/6271
it('should not have a run-time error if no errors are thrown and there are operators', () => {
expect(() => {
of(1, 2, 3).pipe(
map(x => x + x),
map(x => Math.log(x))
)
.subscribe();
}).not.to.throw();
});

afterEach(() => {
config.useDeprecatedSynchronousErrorHandling = false;
});
Expand Down
10 changes: 6 additions & 4 deletions src/internal/Observable.ts
Expand Up @@ -241,8 +241,8 @@ export class Observable<T> implements Subscribable<T> {
* REMOVE THIS ENTIRE METHOD IN VERSION 8.
*/
private _deprecatedSyncErrorSubscribe(subscriber: Subscriber<unknown>) {
let dest: any = subscriber;
dest._syncErrorHack_isSubscribing = true;
const localSubscriber: any = subscriber;
localSubscriber._syncErrorHack_isSubscribing = true;
const { operator } = this;
if (operator) {
// We don't need to try/catch on operators, as they
Expand All @@ -253,7 +253,7 @@ export class Observable<T> implements Subscribable<T> {
try {
this._subscribe(subscriber);
} catch (err) {
dest.__syncError = err;
localSubscriber.__syncError = err;
}
}

Expand All @@ -262,6 +262,7 @@ export class Observable<T> implements Subscribable<T> {
// look to see if there's any synchronously thrown errors.
// Does this suck for perf? Yes. So stop using the deprecated sync
// error handling already. We're removing this in v8.
let dest = localSubscriber;
while (dest) {
// Technically, someone could throw something falsy, like 0, or "",
// so we need to check to see if anything was thrown, and we know
Expand All @@ -275,7 +276,8 @@ export class Observable<T> implements Subscribable<T> {
}
dest = dest.destination;
}
dest._syncErrorHack_isSubscribing = false;

localSubscriber._syncErrorHack_isSubscribing = false;
}

/** @internal */
Expand Down