-
Notifications
You must be signed in to change notification settings - Fork 66
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
MonadError.map should not directly translate to zio.map #330
Comments
To check the behavior, I've created this test which passes:
|
@domdorn IMO the best fix would be in the library, which is relying on behavior that is undefined in Cats Effect. Other libraries like http4s and Doobie successfully cleaned up their undefined use of partial functions and no longer have this issue. |
@jdegoes so would you say, that the change I proposed here bot4s/telegram#106
to
would be the right approach? I was actually surprised that the MonadError from cats for Future transformed the thrown exception, but then again, I'm no expert in cats and have only read the cats book once. |
Ok, I will try to make this library move to proper effects. We could even make this explicit by providing two MonadErrors.. a pure one (the current implementation) and one that just safeguards wherever possible (with obviously reduced performance). |
This is only possible if the error type is fixed to |
Related to #277 |
Can we close this? I don't think it is actionable. |
hmm.. in the lib I'm integrating with, I created my own monad error which gracefully handles errors.. I'm quite sure others will also stumble upon this. However, I don't have any hard feelings about closing it. |
I agree it can be a problem if you have libraries that incorrectly throw exceptions within |
I'm just trying to integrate a lib (https://github.com/bot4s/telegram/) that uses cats effect and I'm using the
interop-cats
module to get hold off aCatsMonadError
.The library uses map(f)
(
https://github.com/bot4s/telegram/blob/c40d679be5865d1a5caa897e0c0f2307922a0cca/core/src/com/bot4s/telegram/clients/SttpClient.scala#L79-L81
) where f can throw an exception ( https://github.com/bot4s/telegram/blob/c40d679be5865d1a5caa897e0c0f2307922a0cca/core/src/com/bot4s/telegram/api/RequestHandler.scala#L113-L120) .
In my local app, I've now overridden the map in
interop-cats/interop-cats/shared/src/main/scala/zio/interop/cats.scala
Lines 275 to 276 in 06a80e2
from
to
I'm also wondering if
should be really implemented this way, as I've noticed that ,e.g. the library is using stuff like
monadError.pure(logger.debug("blabla"))
so I think it should be( https://github.com/bot4s/telegram/blob/c40d679be5865d1a5caa897e0c0f2307922a0cca/core/src/com/bot4s/telegram/api/RequestHandler.scala#L34-L37 )
As I'm in no way an expert in this area, any advice would be greatly appreciated!
To integrate with the library, I've created the following class in my project:
The text was updated successfully, but these errors were encountered: