dave08
05/28/2024, 11:54 AMsimon.vergauwen
05/28/2024, 12:09 PMtry/catch
because I wanted to limit foreign things, since there is people not familiar with Arrow at all also following the talks.
The nested recover is indeed super annoying, but not fixable until we get context parameters I am afraid. Then we could do something like:
recover(
{ context(Raise<E1>, Raise<E2>) () -> A },
{ e1: E1 -> A }
{ e2: E2 -> A }
)
simon.vergauwen
05/28/2024, 12:10 PMAnd last, you put the transaction OUTSIDE the recover, whereas in the presentation it was inside... (as far as I remember...?).You're right, I think I accidentally pushed that when I was talking to someone before the actual talk 😅 I pushed a fixed
dave08
05/28/2024, 12:11 PMbut not fixable until we get context parameters I am afraid.So that feature is not available in the current context parameters implementation?
dave08
05/28/2024, 12:12 PMsimon.vergauwen
05/28/2024, 12:13 PMdave08
05/28/2024, 12:15 PMsimon.vergauwen
05/28/2024, 12:16 PMsimon.vergauwen
05/28/2024, 12:17 PMsimon.vergauwen
05/28/2024, 12:17 PMsimon.vergauwen
05/28/2024, 12:20 PMdata class MyError(val msg: String)
context(Raise<MyError>)
fun hello(name: String): String {
ensure(name.isNotBlank()) { MyError("Name is blank") }
return "Hello, $name"
}
fun MyError.toStatusCode(): HttpStatusCode = TODO()
io.arrow.ktor.get("MyGetter", MyError::toStatusCode) {
val name = path("name") // raises HttpStatusCode.NotFound
hello(name) // Raises MyError which is automatically translated through `MyError::toStatusCode`
}
simon.vergauwen
05/28/2024, 12:21 PMRaise
DSL for Ktor where HttpStatusCode
is the error, and you use withError
, to turn your own types into HttpStatusCode
and then you can call them from within the Ktor Raise DSL.simon.vergauwen
05/28/2024, 12:22 PMsimon.vergauwen
05/28/2024, 12:23 PMexposed {
// any SQLException is turned into a nice Raise<SQLState> where SQLState is an enum of all SQL errors.
}
dave08
05/28/2024, 12:28 PMdb.runQuery(...)
to transform exceptions to raise errors, but it seems like a Raise DSL might be nicer... is it easy to make (maybe have a common set of errors for multiple db libraries, and have an implementation for each? A bunch use Sql Delight for KMP, and there's probably others... somehow unifying error handling for them might be nice if possible...)simon.vergauwen
05/28/2024, 12:29 PMdave08
05/28/2024, 12:31 PMsimon.vergauwen
05/28/2024, 12:54 PM