Error handling with effect scope and exceptions. #2879
Replies: 2 comments
-
|
Hey @KristianNedrevold, Thanks for opening this ticket! Such an API is indeed still missing. Since currently the pattern is In the 2.x.x API we have following signature, which we can back port to suspend fun <E, A> Raise<E>.catch(
block: suspend Raise<E>.() -> A,
catch: suspend Raise<E>.(Throwable) -> A
): AIt's a bit more higher-level since it abstracts |
Beta Was this translation helpful? Give feedback.
-
|
I ran into this again recently. inline fun <reified T: Throwable, Error, R> Raise<Error>.withCatch(transform: (T) -> Error, block: () -> R) = catch(block) { t: T -> raise(transform(t)) }This can help simplify the pattern at hand here |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey. I'm not sure if this should be posted under discussions or issues, but as context receivers are still experimental I figured this might be the right place.
A lot of my functions that interact with APIs I don't own look like
When using EffectScope we can handle exceptions in the function call and map it to some domain error
If we want to handle it at the call site we can do something like this
Handling the exceptions at the call site is what I think is the most idiomatic solution, but it also requires exceptions to be exceptional. This is often not the case when dealing with external APIs. It would be nice if we could have a idiomatic way to catch and map exceptions to some sort of domain error type.
Maybe something like:
Beta Was this translation helpful? Give feedback.
All reactions