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

Error Handling #3072

Closed
adc613 opened this issue Nov 14, 2017 · 4 comments
Closed

Error Handling #3072

adc613 opened this issue Nov 14, 2017 · 4 comments

Comments

@adc613
Copy link

adc613 commented Nov 14, 2017

RxJS version:
5.5

Code to reproduce:

const subject = new Subject<number>();

it('will not receive error', () => {
  const s1 = subject.subscribe(() => {});  // No error handler

  const errorSpy = jasmine.createSpy('subscription error spy')
  const s2 = subject.subscribe(() => {}, errorSpy);
  expect(() => {
    subject.error(1);
  }).toThrow(1);
  expect(errorSpy).toHaveBeenCalled();  // Will fail
});

it('will receive error', () => {
  const s1 = subject.subscribe(() => {}, () => {});  // With error handler

  const errorSpy = jasmine.createSpy('subscription error spy')
  const s2 = subject.subscribe(() => {}, errorSpy);
  expect(() => {
    subject.error(1);
  }).not.toThrow(1);
  expect(errorSpy).toHaveBeenCalled(); // Will pass
});

Expected behavior:
All subscriptions should receive error events.

Actual behavior:
A race condition is created where only the first subscribers receive an error event. Once one subscribe doesn't override the default error handler an error is thrown and code execution is halted.

Additional information:
This is been an issue for us when dealing with XML requests. Some of our code relies on receiving an error event. In our codebase we now have to be very careful and can't rely on publicly exposed observables to receive errors.

@kwonoj
Copy link
Member

kwonoj commented Nov 14, 2017

it is known behavior of unhandled subscriber can stop upstream sources, and for those reason we have introduced #3062 to follow TC39 proposal - and as it's breaking changes we're targeting next major for this.

@adc613
Copy link
Author

adc613 commented Nov 16, 2017

For anyone else who's had the same issue, we've come up with a temporary fix that works for our use case:

observable = Observable.fromPromise(observable.toPromise())

@jayphelps
Copy link
Member

Consolidating the discussion to #2145 (though there's nothing actionable, its as-designed in v5 and v6 changes it)

@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants