Skip to content

Commit 84216da

Browse files
atscottAndrewKushnir
authored andcommitted
fix(core): catch errors from source signals outside of .next (#49769)
From Ben: > When dealing with any reactive function call you don't control > like `observer.next()` (or anything similar), you want to catch the error > in the producer call, in this case `signal()`. You don't want to catch errors > in the `observer.next` call itself. PR Close #49769
1 parent f43d407 commit 84216da

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/core/rxjs-interop/src/to_observable.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ export function toObservable<T>(
4343
// references to `source` to be dropped if the `Observable` is fully unsubscribed and thrown away.
4444
return new Observable(observer => {
4545
const watcher = effect(() => {
46+
let value: T;
4647
try {
47-
observer.next(source());
48+
value = source();
4849
} catch (err) {
4950
observer.error(err);
51+
return;
5052
}
53+
observer.next(value);
5154
}, {injector, manualCleanup: true});
5255
return () => watcher.destroy();
5356
});

0 commit comments

Comments
 (0)