jdonaldson / promhx

A promise and functional reactive programming library for Haxe
MIT License
145 stars 24 forks source link

Handle only specific errors in errorPipe / errorThen #48

Open mcheshkov opened 9 years ago

mcheshkov commented 9 years ago

I want to handle specific error in errorPipe and let all others fall through, just as catch do. To do that I use rethrow, and catch with specific type. But I didn't find a place where errors thrown from errorPipe / errorThen callback is caught. And, continuing try/catch analogy one could throw from catch block and catch that exception higher in call stack.

hexonaut commented 9 years ago

I would return a rejected promise from the errorPipe to do that behaviour. Although I agree regular exceptions thrown from catchError/errorThen/errorPipe should enter the regular promise exception flow.

mcheshkov commented 9 years ago

Actually this would not help - check errorPipe source. There's issue similar to #38

The promise returned from errorPipe is not in _update chain of piped - promise from callback. But the promise that piped.then return (and which is thrown away) is. So if piped is rejected that piped.then callback will never get called, and error will go down the _update chain of piped, which contain only thown away promise, and all you add yourself in callback before returning.

This can be fixed by using AsyncBase.link on (piped, ret) instead of then

jdonaldson commented 9 years ago

I'll check into this... seems useful. I ignored thrown errors in the error handlers because it seemed confusing which part of the promise chain should respond to those.

jdonaldson commented 9 years ago

You'll see that the promise returned from errorPipe is not in the _update chain. This is actually impossible because that promise doesn't exist until the method is invoked. Instead, a proxy async is added to _update. Errors, etc. are routed through that. I'm still confused how this is causing problems... perhaps check the latest promhx update and see if some of the error handling fixes helped you.

jdonaldson commented 9 years ago

The ability to handle specific parameter in cachErrors (per the bug title) is interesting, but unfortunately will require some much more complicated code. I'll mark this as an enhancement and see if I can add it to v2.