-
Notifications
You must be signed in to change notification settings - Fork 18
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
Consider using SuppressedError
when invoking a callback in error steps
#177
Comments
So this probably shouldn't be done for I'm now mixed whether it's even worth doing for There is actually one place in obs.catch((error) => {
// We can't catch the error from Observable.from
return null;
}); so it might be worth doing a |
There would not be any errors suppressed in any of the above scenarios. The only place that someone could have a "suppressed" error would be a situation where somebody called The only one that's a little bit weird is |
But the idea is that the error |
I spent some time looking into this more. The fundamental question is: when should
So is the observable case more similar to explicit resource management, or to try/catch? From what I can tell, the reason for introducing Whereas, in the normal try/catch case, developer code was able to see both errors. There's no clear hierarchy to them, besides the temporal order. Often, the developer is intentionally meaning to overwrite I don't quite understand the relevant |
There's only really one scenario I can think of where an error is (sort of) "suppressed" in an Observable: const errorsImmediately = new Observable((subscriber) => {
subscriber.error(new Error('this is emitted'))
subscriber.error(new Error('this is reported, not emitted'))
})
errorsImmediately.subscribe({
error: (e) => {
e.message === 'this is emitted' // true
}
})
window.addEventListener('error', (e) => {
e.message === 'this is reported, not emitted'; // true
}) Since the EDIT: This is the same thing too... new Observable((subscriber) => {
subscriber.error(new Error('this is emitted'))
throw new Error('this is reported');
}) |
The
catch()
andinspect()
operators have internal observers whose error steps invoke a developer-supplied callback with the given error value they receive. If that callback throws an error, then we must invoke Subscriber'serror()
method with the error thrown from the callback instead of the original error they intended to surface. This clobbering of the original error is exactly whatSuppressedError
intends to alleviate (first mentioned in #174), so we should consider using it in those operators.The text was updated successfully, but these errors were encountered: