-
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
MergeMap throws uncatchable errors #5344
Comments
I think I found where the problem comes from: export const subscribeToPromise = <T>(promise: PromiseLike<T>) => (subscriber: Subscriber<T>) => {
promise.then(
(value) => {
if (!subscriber.closed) {
subscriber.next(value); // Here's the problem!
subscriber.complete();
}
},
(err: any) => subscriber.error(err)
)
.then(null, hostReportError);
return subscriber;
}; The problem is Because Here's a simplified example: Promise.resolve(2)
.then(
v => {
produceErr();
},
err => console.log('ERR') // Never reached
)
.then(null, hostReportError);
function produceErr () {
throw new Error('err!');
}
function hostReportError () { console.log('caught!') }; I think one solution would be to surround that logic with a try {
subscriber.next(value);
subscriber.complete();
} catch (err) {
subscriber.error(err);
} |
|
I thought my problem was other, related, but different of this issue... Here is the reproduction of the problem I had: https://stackblitz.com/edit/rxjs-uncaught-jirbiw?file=index.ts I forget to return an observable on the Should I open other issue? |
It seems that this problem is not reproducible as of v7 ( @tonivj5 In your case from stackblitz, not having the @cartant could you verify and possibly close this issue? |
Not really. The problem is reproducible in |
Thanks @cartant for the confirmation and for the fix. |
* test: add failing invalid ObservableInput tests * fix: catch within innerSubscribe Closes #5344
Closed by #6186 |
Bug Report
Current Behavior
In the sample code below, the TypeError is not caught in the catchError callback, but thrown globally. We can not detect the error in the observable stream and in NodeJS environment this error can cause the whole application to shut down.
(If the provided mergeMap callback throws an Error instead of returning null, the error is handled correctly.)
Reproduction
Expected behavior
The TypeError should not leave the observable stream, should be catchable by catchError the same way like when the
mergeMap(async () => 2)
line does not present.Environment
Possible Solution
Not a solution, just a very hacky workaround for somebody who is affected by this bug: https://stackblitz.com/edit/rxjs-uncaught?file=patch.ts
The text was updated successfully, but these errors were encountered: