-
Notifications
You must be signed in to change notification settings - Fork 3k
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
subscribe() insists on throwing already-handled errors #3560
Comments
Whoops! 🤡 Thanks for reporting and providing a very good minimal reproduction! What ever happens, whoever changes the code should be very careful as 541b49d fixed a ton of people who's uncaught errors were otherwise being swallowed silently, which is IMO an even worse bug. Hopefully test coverage will protect us, but just in case! |
See also #3561. |
@mattflix is it not a duplicate? |
@jayphelps, perhaps so, but #3561 requires an asynchronous element. This one does not. Also, the problematic behaviors were introduced in different versions of RxJS. Feel free to dupe if you feel the underlying cause is the same. I just don't want both variants to get lost. (I was recently bitten by BOTH variants in an attempt to upgrade to 5.5.8, from 5.1.1. Interim solution for me was to only upgrade only as far as 5.4.3.) |
The two issues refer to the same problem; the only difference is the stack frame from which the error is re-thrown. The problem is that the error caught in The (already very helpful) repro can be made even simpler, as the try {
Rx.Observable
.create(observer => { throw `trantrum`; })
.subscribe({
error: err => console.log(`subscribe() received the error: ${ err }`)
});
} catch (err) {
console.log(`subscribe() blew up: ${ err }`);
} The snippet's output will be:
Clearly, if the error is reported via the sink's |
Regarding |
Just to simplify, as I answered this in the other issue: WIthin the function passed to the Observable constructor (aka Observable.create), developers are expected to handle their own errors appropriately and report those to We'd have to have some additional serious design discussions about changing this behavior. Until then, you can solve your issue by either using |
@benlesh, your comment doesn't seem to explain why the same error is delivered BOTH to the Also, I would never want As general comment: The error-handling flow in RxJS has seemingly become mysterious and voodoo-like. Trying to understand and predict what it will do has become frustrating and, in some real examples in my professional work, detrimental to the stability of production code. We now look upon moving to any new version of Rx (major and minor) with great suspicion. |
I would also like to point out that, even if I wanted Trying to write generalized Rx code that can reliably and predictably handle errors, where other observables may be injected (beyond local control) into the sequence being subscribed to, basically becomes impossible in some cases. Putting a |
@jayphelps, you seemed to think the repro highlighted a real problem. Has @benlesh missed something about this issue? Do you agree the current behavior is kosher? (Both handlers being called for a single error.) |
@mattflix I haven't thought hard enough into all the angles to know whether this behavior is in fact ideal, but if it did get introduced as part of my commit then I would assume it's a bug because I did not intend to introduce it. Unless I'm doing something wrong, it doesn't appear that v6 of rxjs has this behavior, which lends credence to it being a bug too. https://stackblitz.com/edit/rxjsv6errorexamplethingy?file=index.js |
IMO, this is somewhat related to the discussions in #3469. That is, there will be some situations in which an error cannot be reported via The difference between this behaviour and the v6 behaviour is that here, the implementation always re-throws - which can lead to the 'double handling' of errors if the In v6, the implementation only reports via the I'd definitely call this a bug. |
what if I want catch from behavior subject ? that make me confuse |
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. |
RxJS version:
5.5.8
Code to reproduce:
Expected behavior:
Actual behavior:
Additional information:
This behavior seems to have been introduced in 5.5.6 with change 541b49d by @jayphelps. Versions < 5.5.6 exhibit the expected behavior.
If the
Observable.create()
call is replaced withObservable.defer()
(that still synchronously throws an error), we get the expected behavior, even with versions >= 5.5.6.If this new 5.5.6 behavior is expected, it seems completely surprising, and very painful to deal with. Why create observables with supposedly self-contained error-handling logic, and yet still have to litter code with try/catch blocks?
The text was updated successfully, but these errors were encountered: